Games & Password
What ARE passwords, anyway?
I don't know about you, but there's nothing worse for me than a “Game Over” screen. And while some games allow you to play a few more times using “continue”, it isn't always enough. And what if your mom unplugs your console because you have to do your homework? These situations make saving and loading a blessing.
But as we know, the console cannot save anything to the cart (except for those carts with a save battery, of course). Therefore, we must come up with another method to save our game progress...on paper!
Option 1: Piece of Cake
So, my goal is to generate a “password,” or a string of characters that will contain the progress of the game and restore it the next time the console starts. All I have to do is select the current game settings, such as the level number and the number of points.
Thus, if I finish the game at level 2 with 10 points, my password will look like a sequence of the following numbers: 2, 10.
Usually, I store all characters as an ASCII table, where the tile code of the letter “A” is 33:
Thus, in order to convert my password values to characters, I have to add 32 to each of the values:
2 + 32 = 34 or “B”
10 + 32 = 42 or “J”
So now I have the password “BJ”, which encodes the values of “level 2” and “10 points.”
Now it's the other way around. In order to convert symbols to values, just subtract 32 from each of them:
34 - 32 = 2
42 - 32 = 10
It’s almost too easy, but nonetheless my task is completed.
Option 2: The Whole Cake
Let's look at the passwords in the Bucky O’Hare game.
Each password of this game contains five slots. Each of these slots is included in the following set: [A..Z, 0..9, “!”, “?”, “★”, “bucky icon”, “↓”, “↑”].
The first password slot is used to store Bucky's energy level and can contain 8 different values.
Bucky’s Slot |
|
3 or 4 or J or K |
low energy level |
5 or I |
medium energy level |
6 or M |
max energy level |
The second password slot contains the state of the blue planet and the energy level of Jenny.
Jenny’s Slot |
|
7 or N |
blue planet not completed |
8 or P |
low energy level, blue planet completed |
9 or Q |
medium energy level, blue planet completed |
! or R |
max energy level, blue planet completed |
The third password slot contains the state of the red planet and the energy level of Dead Eye.
Dead Eye’s Slot |
|
J or T |
red planet not completed |
K or U |
low energy level, red planet completed |
L or W |
medium energy level, red planet completed |
M or X |
max energy level, red planet completed |
The fourth password slot contains the state of the green planet and Blinky's energy level.
Blinky’s Slot |
|
? or 3 or 7 or Y |
green planet not completed |
4 or 8 or Z or “★” |
low energy level, green planet completed |
1 or 5 or 9 or “bucky” or “↑” |
medium energy level, green planet completed |
! or 2 or 6 or “↓” |
max energy level, green planet completed |
And finally, the fifth slot: the yellow planet and Willy’s energy.
Willy’s Slot |
|
? or 3 or J or T |
yellow planet not completed |
4 or K or V or “★” |
low energy level, yellow planet completed |
5 or L or W or “bucky” or “↑” |
medium energy level, yellow planet completed |
6 or M or X or “↓” |
max energy level, yellow planet completed |
Now, when you have such knowledge, you can skip blue and red planet with a password 5RKYT, where
5 = medium Bucky’s energy
R = max Jenny’s energy
K = low Deadeye’s energy
Y = not completed green planet
T = not completed yellow planet
But that's not all. The last two slots are also responsible for storing 4 stages of the toad mother ship:
Stage 1: Cell
Slot 4 (Blinky’s energy) |
Slot 5 |
|
low |
8 or Z |
4 or 5 or 6 or K or L or M or “↑” |
medium |
1 or 9 or “↑” |
|
max |
! or 2 |
Stage 2: Salvage Chute
Slot 4 (Blinky’s energy) |
Slot 5 (Willy’s energy) |
|
low |
4 or “★” |
4 or K |
medium |
5 or “bucky” |
5 or L or “↑” |
max |
6 or “↓” |
6 or M |
Stage 3: Center of Magma Tanker
Slot 4 (Blinky’s energy) |
Slot 5 (Willy’s energy) |
|
low |
! or 8 or Z |
V or “★” |
medium |
1 or 9 or “↑” |
W or “bucky” |
max |
2 |
X or “↓” |
Stage 4: Escape
Slot 4 (Blinky’s energy) |
Slot 5 (Willy’s energy) |
|
low |
4 or “★” |
V or “★” |
medium |
5 or “bucky” |
W or “bucky” |
max |
6 or “↓” |
X or “↓” |
So, if you want to start the game immediately from the last level and with the maximum energy level of all characters, your password should look like this:
M (max Bucky’s energy)
! (max Jenny’s energy)
X (max Deadeye’s energy)
6 (max Blinky’s energy)
X (max Willy’s energy)
And all together: M!X6X
If any of the characters does not match any value from these tables, the password is considered incorrect. This makes “hacking” a password tedious, because if you don’t know the logic of these tables, you will have to sort through a lot of character combinations to find at least one correct password.
This is a good method, but there is one more.
Option 3: Checksum
Quite often, passwords in games include a checksum. This value is necessary in order to check the password for validity and to exclude brute force passwords.
Let's try to create a password system with a checksum. I used this method in earlier versions of The Meating.
So, my goal is to generate 8 symbols of password from the set of characters 0..9 and A..Z, which are located in the tileset starting from tile 0x80 as follows:
My password should contain the world number (0-5), level number (0-9), difficulty level (0-1 for easy and hard mode), the number of items (0-5), and a random value to make the password more varied.
So, the structure of my password fields will look like this:
1 |
Random encryption mask 1 |
unsigned char xorA |
2 |
Random encryption mask 2 |
unsigned char xorB |
3 |
Random encryption mask 3 |
unsigned char xorC |
4 |
World number 1 to 6 + difficulty bit |
unsigned char iWorld |
5 |
Level number 1 to 10 |
unsigned char iLevel |
6 |
Items count 1 to 6 |
unsigned char iItems |
7 |
Random value |
unsigned char rand1 |
8 |
Checksum |
unsigned char checkSum |
Password generation algorithm
1. Generate a random 8-bit value
xValue = rand8()
2. Mask the high bits to keep only the low 5 bits
xValue = xValue AND 0x1F
3.Set the high bit so that the value fits into the alphanumeric tiles range
xorA = xValue OR 0x80
4. Encrypt the world number
iWorld = iWorld XOR xValue
4.1 Add difficulty to this value.
iWorld = (iWorld SHL 1) OR Difficulty
5. Do the same for the level number
xValue = rand8()
xValue = xValue AND 0x1F
xorB = xValue OR 0x80
6. Encrypt the level number
iLevel = iLevel XOR xValue
7. The same for items
xValue = rand8()
xValue = xValue AND 0x1F
xorC = xValue OR 0x80
iItems = iItems XOR xValue
8. Add another random password character
xValue = rand8()
xValue = xValue AND 0x1F
rand1 = xValue OR 0x80
9. Checksum calculation
checkSum = xorA XOR xorB XOR xorC XOR iWorld XOR iLevel XOR iItems XOR rand1;
Password Decryption Algorithm
1. Read all the values from the password and calculate the checksum
xValue = xorA XOR xorB XOR xorC XOR iWorld XOR iLevel XOR iItems XOR rand1
if (xValue == checkSum)
“Password accepted”
else
“Wrong password”
2. Read the world number from the password and use its encryption mask
iWorld = iWorld XOR xorA
3. Discard unnecessary bits
iWorld = iWorld AND 0x0F
3.1. Separate the world number and difficulty
Difficulty = iWorld AND 0x01
3.2. Restore the world number
iWorld = iWorld SHR 1
4. Read the level number from the password and use its encryption mask
iLevel = iLevel XOR xorB
3. Discard unnecessary bits
iLevel = iLevel AND 0x0F
6. Read the items count from the password and use its encryption mask
iItems = iItems XOR xorC
5. Discard unnecessary bits
iItems = iItems AND 0x0F
Well, let's find out how it works
It seems my goal has been achieved. I have encrypted several values in a password with checksum verification using the simplest method based on binary logic.
Of course, this method is not without some drawbacks, but this is quite enough for simple games and small values that you want to encrypt.
There are many games and many other ways to save game progress to a password. You can see these at work in games like Castlevania 3, Prince of Persia, and more. The type of password a game uses will depend on the individual goals of the developers and what they come up with when they are working on a game.
And now, before your mommy will bring back your power supply, try to do some homework: improve my checksum method for your own game. I'm sure you can do it!