1. How the barcode is read

Which digits count, the 40-bit scatter, and the EAN-8 case

Note: this page is about retail JAN/EAN codes. The Datach also reads a Bandai-proprietary card format that works by different rules — see 4. Bandai's barcode.

日本語 | English | Français | Español | Italiano | 한국어

Notation

The 13 digits of an EAN-13 code are numbered d1 to d13 from the left. For 4902773230126 that means d1=4, d2=9, and so on to d13=6. Each digit is a value 0–9; its bits are written b0 (least significant) through b3. So d6=7 gives b0=1, b1=1, b2=1, b3=0.

Only d3 to d12 matter

The first important fact. Only d3 to d12 feed the character and stat calculation. The two leading digits (the country prefix) and the trailing check digit have no effect on the result. So 4902773230126 and 4502773230128 (leading digits changed to 45, check digit recomputed) produce exactly the same result. Players had worked out experimentally that the country prefix "did nothing"; reading the program confirms it is implemented that way.

The check digit being unused by the calculation does not make it free to set arbitrarily. The reader in front of the calculation does verify it, and a sequence that fails that check errors out there. That is why the example above has its check digit recomputed after the prefix change: a code with only the check digit altered will not be read in the first place. Precisely put, the check digit takes no part in computing the result but is used to validate the scan. This came to light while chasing down mismatches in the recorded scans; the story is on the notes page.

The 40-bit scatter

The ten digits d3–d12 are each split into four bits (b0–b3). The resulting 40 bits are redistributed one bit at a time into five internal registers R0–R4, according to a fixed table.

This is what made the system so hard to figure out from the outside. Information from neighbouring digits is flung to distant bit positions, so no amount of experimenting digit by digit ever makes the pattern come out evenly.

The complete table. Columns are the source bit; each cell is the destination register and bit position.

Digitb0 goes tob1 goes tob2 goes tob3 goes to
d3R3 bit7R2 bit4R4 bit4R3 bit4
d4R0 bit5R2 bit0R3 bit6R3 bit3
d5R1 bit1R3 bit0R0 bit3R4 bit0
d6R1 bit3R1 bit5R0 bit0R4 bit3
d7R0 bit7R0 bit1R1 bit7R3 bit2
d8R1 bit4R2 bit3R4 bit5R2 bit2
d9R2 bit7R1 bit0R2 bit6R4 bit6
d10R0 bit2R4 bit1R3 bit1R3 bit5
d11R1 bit2R2 bit1R0 bit4R4 bit2
d12R0 bit6R4 bit7R1 bit6R2 bit5

Forty bits map onto forty bits with nothing left over: the mapping is a bijection. No information is discarded, only rearranged.

After the scatter, read order decides everything

R0–R4 are then treated as a single 40-bit stream, consumed from the front (the most significant bit of R0). The consumption divides evenly into exactly 40 bits:

Bits readUsed forDetail
2Item slot or character slotPage 2
8Weighted draw for the character
3Special move levelPage 3
9 × 3HP, BP, DP (nine bits each)

EAN-8 (the short 8-digit barcode)

The 8-digit codes found on cigarettes and small goods can be read too. The game takes the eight digits o1–o8 and folds them back on themselves to build ten effective digits, then runs exactly the same process as for EAN-13. The effective ten are:

[o3, o4, o5, o6, o7, o8, o7, o6, o5, o4]

So an EAN-8 code carries only six digits of information (o3–o8), and o4–o7 are each used twice. A curious consequence is that the EAN-8 check digit (o8) does take part in the calculation, unlike the EAN-13 case. So on an 8-digit code, mistyping o8 alone surfaces as a shifted stat — which is exactly the property that cracked the mismatched records open.

In short. The barcode is not a random seed. Forty bits are shuffled into fixed positions and read back in a fixed order. The process is completely deterministic: the same barcode always yields the same character.

→ Page 2: choosing the character