To follow up on rrmkdynuupye, the “codes” that one would enter into Game Genie were actually hexadecimal (base sixteen) addresses of where in the game’s memory those variables were stored, followed by the new value to be written in/over.
Sometimes though, like on the Sega Game Gear, the only way to do this was to actually impose the game-genie between the game cartridge and the the system itself, and physically fake “being the cartridge.”
These kind of “exploitative” cheating methods were actually vigorously pursued in court by Nintendo and the like.
Nowadays most cheat codes are actually designed into the game as a feature, but in a way that entering them keeps you from, say, making the high score list.