note 80256 added to ref.hash

From: Date: Sun, 06 Jan 2008 16:26:06 +0000
Subject: note 80256 added to ref.hash
Groups: php.notes 
Request: Send a blank email to php-notes+get-134898@lists.php.net to get a copy of this message
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 ---- Server IP: 203.202.10.60 Probable Submitter: 210.84.10.166 ---- Manual Page -- http://www.php.net/manual/en/ref.hash.php Edit -- https://master.php.net/note/edit/80256 Del: integrated -- https://master.php.net/note/delete/80256/integrated Del: useless -- https://master.php.net/note/delete/80256/useless Del: bad code -- https://master.php.net/note/delete/80256/bad+code Del: spam -- https://master.php.net/note/delete/80256/spam Del: non-english -- https://master.php.net/note/delete/80256/non-english Del: in docs -- https://master.php.net/note/delete/80256/in+docs Del: other reasons-- https://master.php.net/note/delete/80256 Reject -- https://master.php.net/note/reject/80256 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134898) next »