note 80256 deleted from ref.hash by nlopess
| From: | nlopess@php.net | Date: | Sun, 06 Jan 2008 18:48:02 +0000 |
| Subject: | note 80256 deleted from ref.hash by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134899@lists.php.net to get a copy of this message | ||
Note Submitter: zarfmouse
----
For some reason the hash_file('crc32b') algorithm returns a result that is endian swapped
from the result returned by the builtin crc32() function.
You can fix it like this:
<?
function proper_crc32b($file) {
$crc = hash_file('crc32b', $file);
$a = pack('h*', $crc);
$b = unpack('N', $a);
$c = pack('V', $b[1]);
$d = unpack('h*', $c);
$crc=$d[1];
return $crc;
}
$file = $_SERVER['argv'][1];
print "hash_file(crc32b) = ".hash_file('crc32b', $file)."\n";
print "proper_crc32b() = ".proper_crc32b($file)."\n";
print "crc32() = ".dechex(crc32(file_get_contents($file)))."\n";
?>
Which when run on a particular file might output something like this:
hash_file(crc32b) = 5a73a8b2
proper_crc32b() = b2a8735a
crc32() = b2a8735a