Game:
Friend Code:

For each of the games, the unique Identifier used to verify that the friend code
entered is valid, is the 4 character Game code of the region the game was
First released in. For Mario Kart, that would be AMCJ. For Tetris, ATRJ,
For Clubhouse games, ATDE. The reason they use one common game code, is
to prevent duplicate friend codes for a game from being issued.

Up to 2,147,483,648 friend codes can be issued for a single game.

The 12 digit friend code stores a 32 bit number, plus a 7 digit CRC8,
polynomial 0x07. (The CRC8 is acutally 8 bits, just the 8th bit is
chopped off.)

Source code
Original C source code no longer exists, due to phpfi.com being defunct.