I have a hashing function in PHP which is a port of a Java hash function. On my 32-bit, the functions match. However, when running the PHP code on 64-bit OS the results change.
Is there anyway in which I can execute the arithmetic operations independent of the architecture, as if they are always executed on 32-bit system?
Here is my hashing function:
function numericHash( $text, $lessThan = 50 )
{
$hash = 0;
for ( $i = 0; $i < strlen( $text ); $i++ ) {
$b = ord( $text[ $i ] );
$hash += $b;
$hash = intval( $hash );
$hash += ( $hash << 10 );
$hash = intval( $hash );
$hash ^= ( $hash >> 6 );
$hash = intval( $hash );
}
$hash += ( $hash << 3 );
$hash = intval( $hash );
$hash ^= ( $hash >> 11 );
$hash = intval( $hash );
$hash += intval( $hash << 15 );
$hash = intval( $hash );
return bcmod( (string) abs( $hash ), (string) $lessThan );
}