Hi,
I'm curious why I'm getting two different digests of the same message
using crc32() and hash('crc32'). I've tried both hash('crc32') and
hash('crc32b'), and neither match my crc32(). Some example code:
<?php
$message = "foo";
$crc32 = crc32($message);
$hash_crc32 = hash('crc32', $message);
$hash_crc32b = hash('crc32b', $message);
$data = array (
array (
sprintf('%+011d', $crc32), // signed integer
sprintf('%010u', $crc32), // unsigned integer
dechex($crc32), // hexadecimal
sprintf('%032b', $crc32) // binary
),
array (
sprintf('%+011d', hexdec($hash_crc32)),
sprintf('%010u', hexdec($hash_crc32)),
$hash_crc32,
sprintf('%032b', hexdec($hash_crc32))
),
array (
sprintf('%+011d', hexdec($hash_crc32b)),
sprintf('%010u', hexdec($hash_crc32b)),
$hash_crc32b,
sprintf('%032b', hexdec($hash_crc32b))
)
);
echo join("\n", array_map(create_function('$vals', 'return join(" =>
", $vals);'), array_values($data)));
?>
Output:
-1938594527 => 2356372769 => 8c736521 => 10001100011100110110010100100001
-1513816503 => 2781150793 => a5c4fe49 => 10100101110001001111111001001001
+0560296844 => 0560296844 => 2165738c => 00100001011001010111001110001100
Not only do none of these match, but when I try with a message that I
intend to validate and am given a CRC32 to check against, the given
CRC32 hash does not match any of these three. Granted, the message I'm
trying to validate could in fact be invalid, but regardless there's
still the discrepancy between crc32() and hash('crc32'). Is this
expected behavior?
Thanks,
Morgan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php