=0;--$i,$temp=0) { $temp = $bigint1[$i] + $bigint2[$i]+$carry; if($temp & 0x100) { $carry = 1; } else { $carry = 0; } $bigint1[$i] = $temp & 0xFF; } } function bigint_mul() { global $bigint1; global $bigint2; global $bigresult; for($i = 0; $i < 8; ++$i) { $bigresult[$i] = 0; } for($i = 0; $i < 64; ++$i) { if($bigint2[7] & 0x01) { for ($j = 7, $temp = 0, $carry = 0; $j >= 0; --$j, $temp = 0) { $temp = $bigresult[$j] + $bigint1[$j] + $carry; if($temp&0x100) { $carry = 1; } else { $carry = 0; } $bigresult[$j] = $temp & 0xFF; } } for ($j = 0, $temp = 0, $carry = 0; $j < 8; ++$j, $temp = 0) { $temp=$bigint2[$j]; $bigint2[$j] &= 0xFE; $bigint2[$j] >>= 1; $bigint2[$j] += $carry; if($temp & 0x01) { $carry = 0x80; } else { $carry = 0; } } for ($j = 7, $temp = 0, $carry = 0; $j >= 0; --$j, $temp = 0) { $temp=$bigint1[$j]; $bigint1[$j] &= 0x7F; $bigint1[$j] <<= 1; $bigint1[$j] += $carry; if($temp & 0x80) { $carry = 0x01; } else { $carry = 0; } } } for ($j = 0; $j < 8; ++$j) { $bigint1[$j] = $bigresult[$j]; } } function gen_crc() { global $CRC_Table; for ($i = 0; $i < 256; ++$i) { $crctab = $i; for ($j = 0; $j < 8; ++$j) { if ($crctab & 0x80) { $crctab <<= 1; $crctab ^= 7; } else { $crctab <<= 1; } } $CRC_Table[$i] = $crctab & 0xFF; } } function calc_crc($initial, $data, $length) { global $CRC_Table; $crc = $initial; for ($i = 0; $i < $length; ++$i) { $crc ^= $data[$i]; $crc &= 0xFF; $crc = $CRC_Table[$crc]; } return $crc; } function friendcode($code,$reverse) { global $bigint1; global $bigint2; for ($i = 0; $i < 8; ++$i) { $bigint1[$i] = 0; $bigint2[$i] = 0; } $k = 12; $temp = 0; for ($i = 0; $i < $k; ++$i) { if($reverse==1) { $j = $code[(strlen($code)-1)-$i]; } else { $j = $code[$i]; } if (($j < '0') || ($j > '9')) { if(($j == ' ') || ($j == '-')) { ++$k; continue; } else { return 0; } } $j -= '0'; $bigint2[7] = 0x0A; bigint_mul(); $bigint2[7] = $j; bigint_add(); ++$temp; } return $temp; } function validate_code($code, $magic) { global $bigint1; for($i=0,$j=0;$i<5;++$i) { $j += $bigint1[$i+3]; } if($j == 0x00) return 0; //if ($code == 0x00) return 0; if($bigint1[4] & 0x80) return 0; //if ($code & 0x80000000) return 0; $crc_data[0] = $bigint1[7]; $crc_data[1] = $bigint1[6]; $crc_data[2] = $bigint1[5]; $crc_data[3] = $bigint1[4]; //$crc_data[0] = ($code >> 0) & 0xFF; //$crc_data[1] = ($code >> 8) & 0xFF; //$crc_data[2] = ($code >> 16) & 0xFF; //$crc_data[3] = ($code >> 24) & 0xFF; $crc_data[4] = ($magic >> 0) & 0xFF; $crc_data[5] = ($magic >> 8) & 0xFF; $crc_data[6] = ($magic >> 16) & 0xFF; $crc_data[7] = ($magic >> 24) & 0xFF; $strCRC = ''; foreach ($crc_data as $crcItem) { $strCRC .= $crcItem; } $checksum = calc_crc(0,$crc_data,8) & 0x7F; $codeShift = $code; // $codeShift = (($code / pow(32,4)) & 0x0FF000); // $codeShift = dechex($codeShift); // $codeShift = substr($codeShift,0,2); // $codeShift = hexdec($codeShift); //if(($codeShift >> 32) & 0x80) return 0; //if(($codeShift >> 32) != $checksum) if($bigint1[3] & 0x80) return 0; if($bigint1[3] != $checksum) { return 0; } else { return 1; } } function getHexOfGameCode($strGameCode) { return (int)hexdec(sprintf("%02x%02x%02x%02x",ord($strGameCode[0]),ord($strGameCode[1]),ord($strGameCode[2]),ord($strGameCode[3]))); } function ValidateFriendCode($strGameCode,$strFriendCode) { $GameCodeE = (int)hexdec(sprintf("%02x%02x%02x%02x",ord($strGameCode[0]),ord($strGameCode[1]),ord($strGameCode[2]),0x45)); $GameCodeJ = (int)hexdec(sprintf("%02x%02x%02x%02x",ord($strGameCode[0]),ord($strGameCode[1]),ord($strGameCode[2]),0x4A)); $GameCodeP = (int)hexdec(sprintf("%02x%02x%02x%02x",ord($strGameCode[0]),ord($strGameCode[1]),ord($strGameCode[2]),0x50)); $GameCodeX = (int)hexdec(sprintf("%02x%02x%02x%02x",ord($strGameCode[0]),ord($strGameCode[1]),ord($strGameCode[2]),0x58)); $reversecode = (int)hexdec(sprintf("%02x",ord($strGameCode[3]))); if($reversecode == 0x52) { $reversecode = 1; } else { $reversecode = 0; } $fcode = friendcode($strFriendCode,$reversecode); if($fcode==0) { return -1; } if($fcode<12) { return -2; } if(validate_code(friendcode($strFriendCode,$reversecode),$GameCodeE)) { return 1; } if(validate_code(friendcode($strFriendCode,$reversecode),$GameCodeJ)) { return 1; } if(validate_code(friendcode($strFriendCode,$reversecode),$GameCodeP)) { return 1; } if(validate_code(friendcode($strFriendCode,$reversecode),$GameCodeX)) { return 1; } return 0; } //All Page related code follows here. Feel free to remove such code if using for your own friend code validator, on your //DS friend code sharing site. ?> CaitSith2's Nintendo WFC Friend code Verifier
Game:
Friend Code:
Game:
Friend Code:
=12) { $result = ValidateFriendCode($_POST[gamecode],$_POST[friendcode]); if($result == 1) { echo "Code is Valid
"; } else if ($result == -1) { echo "Please use numbers only. (Spaces and dashes are permitted)
"; } else if ($result == -2) { echo "The Friend code must be 12 digits
"; } else { echo "Code is Invalid
"; echo "Make sure the code is typed correctly.
"; echo "Also make sure the correct game is selected
"; } } else { echo "The Friend code must be 12 digits
"; } } ?>
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 "; ?>