Pokemon Mystery Dungeon - Passwords

For tools to generate passwords, see the Wonder Mail Generator and the SOS Mail to A-OK Mail Converter..

Wonder Mail Passwords

This page will try to explain in detail how the game decodes a Wonder Mail password.

To begin, the process rearranges the position of each character of the password by using a lookup table. The character at the old position of the password is moved to a new position. For example, the character at position 11 (starting from zero) is moved to position 14 (starting from zero) in the new password.

Old Pos. New Pos.
012
120
29
317
44
515
61
723
83
97
1019
1114
120
135
1421
156
168
1718
1811
192
2010
2113
2222
2316

Then, each character of the password is converted to a 5-bit number:

Character Number
!26
♂ (m)30
♀ (f)27
+10
-22
...11
09
124
225
328
416
517
61
72
86
97
?0
C19
F8
H20
J21
K23
M18
N3
P4
Q29
R5
S12
T13
W31
X14
Y15

In a process called bit packing, where bits are packed into 8-bit bytes without waste of space, the password is converted into 15 binary bytes.

To understand the process further, we will give an example.

Suppose we are packing the three-character password 2FT. The process is to convert each character to a number and then pack each number into a single mass. To make the bit packing clearer, we will show the binary representation of each number. (In a binary representation, each digit stands for one bit.)

Character Number Binary
22511001
F801000
T1301101

Each number is packed by starting with the rightmost bit of the number and storing that bit on the rightmost position of the result. Then the next rightmost bit is retrieved and stored, and so on until all bits are stored. If there is no room to fit more bits, the next byte of the result is used.

After the bit packing process, any remaining bits of the last result byte are filled with zeros to make the byte 8 bits long.

In this case here is how the result would look when packed this way.

Character Number Binary Result
2251100111001 (1 byte)
F80100000011001 (1 byte, no room to store whole number)
F80100000011001 | 01 (2 bytes, remaining bits are stored in next byte)
T250110100011001 | 0110101 (2 bytes)
------00011001 | 00110101 (2 bytes, remaining bits are filled with zeros)

In the same way, the 24-character password is converted into a 15-byte password. (The 24 characters make up 120 bits, and the 15 bytes also make up 120 bits.)

Then from the packed password, the game calculates the password's checksum. The pseudocode below calculates the checksum (the code assumes that, for example, the first byte of the password is at position 0):

sum=0                              // set the sum to 0
PasswordLength=15                  // the password is 15 bytes long
for(i=1;i<PasswordLength;i++){     // Skip the first byte of the password
 sum+=Password[i]+(i+1)            // i'th byte of password plus i plus 1
 sum&=0xFF                         // AND the checksum with 255 to make it a single byte
}

The checksum is compared with the first byte of the password. If they match, then the password is valid.

Next, the first byte of the password is removed, making the password 14 bytes long. (The first byte is merely a checksum, as already mentioned above.)

As a final step, the password is converted into a Wonder Mail by unpacking the bits of the 14-byte password. Bit unpacking is the reverse of bit packing. This process can be better understood with another example.

Suppose we are unpacking bits from the two-byte sequence {45, 226}. These two bytes are represented in binary as {00101101, 11100010}. Bit unpacking starts with the rightmost bit of the first byte. That bit is retrieved and stored in the rightmost position of the result. Then the next rightmost bit is retrieved and stored, and so on until all bits are stored. If a bit cannot be retrieved or stored in the source or the result, then the next byte of the source or result is used.

Here are the results of a sample bit unpack using the two bytes shown above.

Bits to Unpack Bits in Sequence Result
400101101 | 111000101101
300101101 | 11100010010
300101101 | 11100010100*
500101101 | 1110001011000

* Top bit of 1st byte, bottom 2 bits of 2nd byte.

The bits of the password are stored in different positions in the Wonder Mail. Here is the order in which the bits are unpacked and stored in the Wonder Mail.

Position Bits to Unpack Description
04Mail type, must equal 5 for Wonder Mail
13Mission type
24Unknown, usually equal to 0
129Client Pokemon (2 bytes)
149Target Pokemon (2 bytes)
168Item to find/deliver, safe to set to 9 if not applicable
174Reward type
188Item reward, safe to set to 9 if not applicable
196Friend Area reward, safe to set to 0 if not applicable
8243 bytes with unknown purpose, safe to set each to 255
47Dungeon
57Floor (e.g. set to 2 for 2nd floor)

Mission types:

Reward Types:

SOS and A-OK Mail Passwords

These types of passwords have a very similar decoding process to the one for Wonder Mail passwords. Some differences are explained here. Each SOS and A-OK Mail password is 54 characters long. The table below shows the positions that the characters are rearranged to:

Old Pos. New Pos.
023
116
237
345
44
541
652
71
88
939
1025
1136
1247
130
1412
153
1633
1720
1828
199
2049
2153
2251
2331
2411
252
2613
2714
2834
295
3046
3127
3217
3318
3419
3529
3638
3748
3822
3932
4042
4115
426
4326
4430
4510
4644
4750
4835
497
5040
5121
5243
5324

Then the 54-character password is packed into a 34-byte password as described above. (The 54 characters make up 270 bits, and the 34 bytes make up 272 bits, so the last 2 unused bits are filled with zeros, as described above.)

Then the checksum is calculated for the password and compared with the password's first byte, as described above.

Next, the first byte of the password is removed, making the password 33 bytes long.

Finally, the bits are unpacked to make an SOS or A-OK Mail, in the order shown below.

Position Bits to Unpack Description
04Mail type, must equal 1 for SOS Mail, 4 for A-OK Mail, and 5 for Thank-You Mail
47Dungeon
57Floor (e.g. set to 2 for 2nd floor)
824Unknown (3 bytes)
129Pokemon to be rescued (2 bytes)
1632Mail ID (4 bytes)
2080Pokemon's nickname (10 bytes), 0 marks end of name if shorter than 10 bytes
328Unknown, safe to set to 1 (if Thank-You Mail) or 0
338Reward item, safe to set to 0 if not Thank-You Mail
348Unknown, safe to set to 0
3632ID of rescue team seeking help (4 bytes)
4032ID of rescue team giving help (4 bytes); for SOS Mail, this is 0; for A-OK Mail, safe to set to rescue team seeking help
448Rescue chances left; when converting to A-OK Mail, subtract 1 from this
451Unknown, safe to set to 0

Example of Bit Packing and Checksum Calculation

Bit packing result for a 24-character password.

Character Number Binary
41610000
10000
X1401110
11010000 | 01
0901001
11010000 | 0100101
41610000
11010000 | 00100101 | 1000
N300011
11010000 | 00100101 | 00111000 | 0
?000000
11010000 | 00100101 | 00111000 | 000000
7200010
11010000 | 00100101 | 00111000 | 10000000 | 000
P400100
11010000 | 00100101 | 00111000 | 10000000 | 00100000
6100001
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 00001
J2110101
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 10
P400100
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 0010010
?000000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 0000
12411000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
1
?000000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
000001
32811100
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 111
#3011110
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111
W3111111
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111
9700111
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 00
41610000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 1000000
?000000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 0000
?000000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 0
?000000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 000000
?000000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 000
?000000
11010000 | 00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000

15-byte password result:

208 | 37 | 56 | 128 | 32 | 161 | 18 | 128
1 | 247 | 255 | 64 | 0 | 0 | 0

Now the checksum is calculated. The checksum begins at 0. The first byte of the password (208) is ignored in the calculation.

Position Byte Byte + Position Sum = Sum + Byte
+ Position
Sum = Sum AND 255
137383838
256589696
3128131227227
432362637
5161166173173
61824197197
712813533276
8198585
924725634185
1025526535094
116475169169
12012181181
13013194194
14014208208

The resulting checksum is 208, which matches the first byte of the password (208).

The first byte of the password is removed in the last step, which is unpacking the bits.

Position Bits to Unpack Binary Bytes Description
0401015Mail type, must equal 5 for Wonder Mail
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
130102Mission type
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
2400000Unknown, usually equal to 0
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
12900000111 | 07 | 0Client Pokemon (2 bytes, little endian)
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
14900001000 | 08 | 0Target Pokemon (2 bytes, little endian)
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
168000010019Item to find/deliver
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
17401015Reward type
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
188000010019Item reward
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
1960000000Friend Area reward
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
82400000011 | 11101110 | 111111113 | 238 | 2553 bytes with unknown purpose
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
4700000011Dungeon
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000
5700000011Floor (e.g. set to 2 for 2nd floor)
00100101 | 00111000 | 10000000 | 00100000 | 10100001 | 00010010 | 10000000
00000001 | 11110111 | 11111111 | 01000000 | 00000000 | 00000000 | 00000000

< Back