function get_hash($str) { // Fix for Unicode support by Naki-BoT for ($i = 0; $i < strlen($str); $i++) { // PvPGN hash is case insensitive but only for ASCII characters if (ord($str[$i]) < 128) { $str[$i] = strtolower($str[$i]); } } $x = str2blks_pvpgn($str); $a = 0x6745 << 16 | 0x2301; $b = 0xefcd << 16 | 0xab89; $c = 0x98ba << 16 | 0xdcfe; $d = 0x1032 << 16 | 0x5476; $e = 0xc3d2 << 16 | 0xe1f0; for ($i = 0; $i < count($x); $i += 16) { $olda = $a; $oldb = $b; $oldc = $c; $oldd = $d; $olde = $e; for ($j = 0; $j < 16; $j++) { $w[$j] = $x[$i + $j]; } for ($j = 0; $j < 64; $j++) { $ww = $w[$j] ^ $w[$j + 8] ^ $w[$j + 2] ^ $w[$j + 13]; $w[$j + 16] = 1 << $ww % 32; } for ($j = 0; $j < 80; $j++) { if ($j < 20) { $t = safe_add(safe_add(safe_rol($a, 5), ft($j, $b, $c, $d)), safe_add(safe_add($e, $w[$j]), kt($j))); } else { $t = safe_add(safe_add(safe_rol($t, 5), ft($j, $b, $c, $d)), safe_add(safe_add($e, $w[$j]), kt($j))); } $e = $d; $d = $c; $c = safe_rol($b, 30); $b = $a; $a = $t; } // Fix for 64-bit OS by Pada $a = safe_add($t, $olda) & 4294967295.0; $b = safe_add($b, $oldb) & 4294967295.0; $c = safe_add($c, $oldc) & 4294967295.0; $d = safe_add($d, $oldd) & 4294967295.0; $e = safe_add($e, $olde) & 4294967295.0; } return sprintf("%08x%08x%08x%08x%08x", $a, $b, $c, $d, $e); }
function pvpgn_hash($str) { $x = str2blks_pvpgn($str); $a = 0x6745 << 16 | 0x2301; $b = 0xefcd << 16 | 0xab89; $c = 0x98ba << 16 | 0xdcfe; $d = 0x1032 << 16 | 0x5476; $e = 0xc3d2 << 16 | 0xe1f0; for ($i = 0; $i < sizeof($x); $i += 16) { $olda = $a; $oldb = $b; $oldc = $c; $oldd = $d; $olde = $e; for ($j = 0; $j < 16; $j++) { $w[$j] = $x[$i + $j]; } for ($j = 0; $j < 64; $j++) { $ww = $w[$j] ^ $w[$j + 8] ^ $w[$j + 2] ^ $w[$j + 13]; $w[$j + 16] = 1 << $ww % 32; } for ($j = 0; $j < 80; $j++) { if ($j < 20) { $t = safe_add(safe_add(safe_rol($a, 5), ft($j, $b, $c, $d)), safe_add(safe_add($e, $w[$j]), kt($j))); } else { $t = safe_add(safe_add(safe_rol($t, 5), ft($j, $b, $c, $d)), safe_add(safe_add($e, $w[$j]), kt($j))); } $e = $d; $d = $c; $c = safe_rol($b, 30); $b = $a; $a = $t; } $a = safe_add($t, $olda); $b = safe_add($b, $oldb); $c = safe_add($c, $oldc); $d = safe_add($d, $oldd); $e = safe_add($e, $olde); } return sprintf("%08x%08x%08x%08x%08x", $a, $b, $c, $d, $e); }