Walda

Walda Pepper (Japanese: アヤノ Ayano) is a young girl in Rustboro City who is very sick. She has only appeared in. Her father bought her multiple Poké Dolls—such as and the —to cheer her up, but it has not worked. If the player is able to say something to make her laugh, her father will reward them with a new wallpaper for the Pokémon Storage System.

Words that will make Walda laugh usually consist of random characters and depend on the player's Trainer ID number.

Passphrase calculation
There are 256 different passphrases for every possible wallpaper Walda's father can grant. The primary components that go into a passphrase are: The final component can be any random number ranging from 0 to 255 (this will be referred to as key). Different values for this number can create vastly different passphrases, but they will all unlock the same wallpaper. This number simply masks and scrambles the other values.
 * The player's Trainer ID (this will be referred to as tid)
 * An index number for the pattern of the wallpaper (pat)
 * An index number for the icon in the wallpaper (ico)
 * A value for the background color, influencing the majority of the pattern (bcolor)
 * A value for the foreground color, influencing the icons and specific parts of the pattern (fcolor)

This section will explain the process of creating a passphrase from the required components, but the game can easily reverse this process to create the proper wallpaper from a given passphrase.

Colors
The colors are 2-byte values that represent the five highest bits of the red, green, and blue values in an RGB color in the manner shown below:



As an example, if the green color used above&mdash;represented as "99FF99" in hexadecimal or  in binary&mdash;were chosen for the wallpaper's background, it would be encoded as   (0x4FF3 or 20,467) for bcolor.

Patterns and icons
There are 16 different possible patterns and 30 possible icons that can be placed within the patterns. They are described below as they are named in the filb.de generator linked at the bottom of this page. A sample of each of the patterns and some of the icons may be seen here.

The icons that are marked with an asterisk (*) are only available in Japanese versions of Pokémon Emerald. If this index is used in an English passphrase, no icon will appear in the resulting wallpaper. This does not apply to the Ribbon wallpaper, however; that wallpaper can be unlocked in the English version of Emerald, but it is slightly different from the Japanese version.

Algorithm
tid, bcolor, and fcolor are all 2-byte values. However, this algorithm deals with the bytes in these values separately. tid1, bcolor1, and fcolor1 will refer to the lowest byte of these values, while tid2, bcolor2, and fcolor2 will refer to the highest byte. For example, if the value of tid is 511, then tid1 is 255 and tid2 is 1.

The player's Trainer ID undergoes a transformation before it is used in the rest of the algorithm.

A 9-byte string is then created by joining all of the current values together as follows:

Next, a bitmask is created using the highest four bits of key. These four bits are repeated to fill the highest 8 bytes of a 9-byte string, with the bits in the lowest byte remaining 0; this string is represented below as mask.

Then, the highest 8 bytes of V are treated as if they are a circular structure (with the lowest bit "connected" back around to the highest bit) and are shifted to the right by  bit positions. After this, the whole 9-bytes are treated as a circular structure and shifted right by 21 bit positions. This result will be referred to below as W.

W is the string that will finally be used to create the passphrase. Since a passphrase requires inputting a full-length word and the maximum length of input differs between Japanese and English games, the method of interpreting W to arrive at the passphrase differs between Japanese and English games.

In English games, every 5 bits in W represent a letter in the passphrase. Since W is a 9-byte string (or 72 bits long), it contains enough bits for 14 full letters, with 2 bits left over. To form the last letter and reach the maximum 15-letter length for English input, the letter effectively wraps back to the top of W, using the two lowest bits of W for the letter's two highest bits and the three highest bits of W for the letter's three lowest bits. Letters can be determined by matching the value of each 5-bit number with a character below: This is largely the first 32 capital and lowercase English letters without vowels, with a select few other letters excluded as well.

So, in an English game, if the first (highest) two bytes of W are, the first three letters of the passphrase will be "S" ( , or 14), "p" ( , or 29), and "Q" ( , or 12). If the last (lowest) byte of W is also, then the last letter of the passphrase will be "P" ( , or 11).

In Japanese games, every 6 bits in W represent a letter in the passphrase. Since W is a 9-byte string (or 72 bits long), this divides W evenly into a maximum length, 12-letter passphrase. Letters can be determined by matching the value of each 6-bit number with a character below: This corresponds to the first 64 characters in the game's Japanese character encoding, offset by 1 to skip the space in the 0 position.

So, in a Japanese game, if the first (highest) two bytes of W are, the first two letters of the passphrase will be "え" ( , or 3) and "め" ( , or 33).

Note that when the original 9-byte string U (and then V) was being manipulated, the random bitmask and shifting based on key avoided the part of the string (the lowest byte) that contained key itself. The only time key is manipulated is in the final, set shift by 21 bits. Because of this, the game can know exactly how to retrieve key from a passphrase and reverse the entire algorithm to extract the wallpaper components from the passphrase.