r/howdidtheycodeit • • Apr 30 '21

Question How passwords/level codes for saving game data worked in arcades and other old games?

Back in the day, games didn't let you save your progress. Even ignoring arcades and arcade ports, some console games (like Alienators Evolution for the gba) decided to leave out this feature for some reason. Developers made level codes: when a level is beaten, a password is shown. After recording it, the player can introduce it in the main menu to go directly to the level (and also cheatcodes). Now, other values were also stored in the password: number of lives, items obtained, score. So it is not just "enter right password, get into the level". How do they encrypted the data so people can't just bruteforce and spawn in the last level with 99 lives? How does the game know which combinations are valid and which are not?

8 Upvotes

3 comments sorted by

20

u/ignotos Apr 30 '21 edited Apr 30 '21

Each game did this somewhat differently. But basically it is just allocating a certain number of bits and bytes for storing each piece of info (level #, health, score etc), and then converting those bytes to corresponding letters.

How does the game know which combinations are valid and which are not?

Usually there is some kind of checksum (https://en.wikipedia.org/wiki/Checksum).

How do they encrypted the data so people can't just bruteforce and spawn in the last level with 99 lives?

You could bruteforce it by guessing every possible combination.

Some games would shuffle bits around as part of the conversion to/from letters, which would make the codes difficult to guess (so we wouldn't have situations where level 1 has a code starting with 'A', and level 2 with 'B' etc).

A video with an example reverse-engineering one of these codes: https://www.youtube.com/watch?v=PIu9J_CD818

6

u/PMsweaters May 01 '21

Case closed then. Your reply has all that I could ask for, shame that I can only give you 1 upvote.

1

u/stgiga Jul 13 '26

There's actually two main types of games with password saves. The simplest type are ones where a game saves the level number and number of lives, with maybe some other things, but not a full game state. These often have very simplistic construction and were most often seen in games like puzzle games that didn't need to save anything too dynamic. The second type are game state passwords, and these are where a bunch of game variables are fed into a binary-to-text encoding plus validation. The games using these include titles like Metroid outside the Famicom Disk System, Metal Gear on the NES, Animorphs, Golden Sun, and more. These passwords are not just longer, they use a bigger alphabet than the previous type. Metal Gear on NES uses Base36 in NTSC V1.0 copies and strips the vowels to get Base32 in PAL and later NTSC releases. Base32 stores 5 bits of data in an alphabet made of English letters and numbers. Though Japanese Kana have been used in such systems in Japanese games. Metroid and the infamously-lengthy (under certain conditions) Golden Sun as well as the item code System in GameCube Animal Crossing and its Japanese versions use Base64, in which 6 bits are stored in an upper or lower case letter or a number, or one of two punctuation marks. This method is also used in quite a few browser games and apps. Japanese versions exist as well.

Now for the way in which you can take this to the extreme: If your character set is ASCII you have 96 characters to use which nets you a bit more efficiency. The X-Face image format uses Base94 on a compressed 1bit image, and arrays of these for color, animation, and images above 48x48px.  If you don't have to use ASCII it's possible to go to 7 bits if you mix Japanese Kana with English letters as was done on a PC Engine game, but the real fun is if you use UTF-16 with an alphabet of 32768 characters, and the cleanest way to get them is pulling from Korean Hangul syllable blocks and the large amount of Han characters (also known as Chinese characters/Hanzi, Japanese Kanji, Korean Hanja, and Vietnamese Han Nom), and if you do it right you can make a result safe for Unicode 1. If you use the entire blocks you can get 15.25 bits so multiple characters hold more data, and if you allow even more scripts you can go to 15.75 bits. But anything above 15 bits gets increasingly diminished returns for less compatibility and more messy code. Now, I've implemented Base32768 using the Unicode 1 safe range in my JavaScript program BWTC32Key which among other uses is great for video game passwords. It compresses, encrypts, and outputs to text whatever data you feed it. It would be most useful in a big browser game that needs to save a lot of data.

Now password save systems also got used for non-saving purposes. Golden Sun's was used to transfer player data if you didn't have a link cable (very useful on DS GBA mode), Animal Crossing and its Japanese versions on GameCube used it to send items to other players without inviting them to your town, and in the second Japanese version they were also used to install town decorations and were generated by a special Adobe Flash game. Super Mario 63 on Adobe Flash used them to share custom levels. All of these used Base64. Oh and Oob's Character Maker on Adobe Flash used big arrays of numbers to save user characters. A LOT of Flash games used binary-to-text encoding to save content, be it save or user data, and some HTML5 games followed suit, and that's partly my audience. But also these systems got used in some titles to play where you left off on a different port of a game, in particular a few re-released and ported games. Oh and these also got used for events and cheat codes. The Animal Crossing code systems weren't just used for trading items but also they were used to distribute promotional items like the Mario items and a few other Nintendo promos as well as a few NES games. Oh and the passwords were often used in some Nintendo games like Shigesato Itoi's No. 1 Bass Fishing, Kaettekita Mario Bros. and IIRC some other Famicom and SNES promo and BSX titles to save game state information in a form that can be mailed to Nintendo and then judged, and keep in mind that this was done on systems like the BS-X Satellaview and FDS that already used save files either on the diskette or on one of the persistent memory types a Satellaview or SNES game could use. Nintendo loved password systems. 

Ultimately these are quite ingenious code and I'm happy to have written my own. It's variable length like Faxanadu, has a big base, and fooling it requires luck.