> $bit ) & 1 ) { $accumulator+=$shifted; //ensure the result stays as an integer settype($accumulator,'integer'); } } return $accumulator; } /* performs a c++ style unsigned long mod */ function CStyleMod($num,$mod) { settype($num,'float'); if ( $num < 0 ) $num += 4294967296; settype($mod,'float'); if ( $mod < 0 ) $mod += 4294967296; if ( $num == $mod ) return 0; if ( $num < $mod ) return $num; $rem=$num; while ( $rem >= 0 ) { $rem -= $mod; } if ($rem < 0 ) $rem += $mod; settype($rem,'integer'); return $rem; } /* this is the actual key generation algorithm supply it with the PC ID # and it will give you the hex key back */ function GenerateKey($theID) { //clip theID to a 32bit integer before we even start settype($theID,'integer'); //implement 'key = theID >> 2' $key=($theID >> 2); //php will not clear most significant 2 bits after shift so we do it manually $key = $key & 1073741823; settype($key,'integer'); //implement 'if key == 0 key = theID << 24' if ($key == 0) $key = $theID << 24; settype($key,'integer'); $key = CStyleMultiply($key,111111); settype($key,'integer'); //implement 'key += theID << 4' $shl = $theID << 4; settype($shl,'integer'); $key += $shl; settype($key,'integer'); //implement 'key *= theID % temp' $modded = CStyleMod($theID,$key); settype($modded,'integer'); $key = CStyleMultiply($key,$modded); settype($key,'integer'); //got the numeric key code - just convert it to a positive unsigned long equiv and then to hex settype($key,'float'); if ( $key < 0 ) $key += 4294967296; $hex = strtoupper(base_convert($key,10,16)); return $hex; } ?>