php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32432 crc32() sometimes gives different values than other CRC32 engines
Submitted: 2005-03-23 18:59 UTC Modified: 2005-03-23 19:10 UTC
From: alex at primafila dot net Assigned:
Status: Not a bug Package: *Encryption and hash functions
PHP Version: 4.3.10 OS: Linux, Darwin
Private report: No CVE-ID: None
 [2005-03-23 18:59 UTC] alex at primafila dot net
Description:
------------
While comparing crc32()'s output with other languages' 
CRC32 functions I note that sometimes the result is 
different. Unfortunately all other engines, such as Perl 
Digest::Crc32, String::CRC32, Archive::Zip, give always  
the same value.

I wasn't able to understand which format leds to this 
misbehaving, and I also tried to run crc32() of failing 
strings' MD5 hashes: the result is different.

Reproduce code:
---------------
#This works:
php -r "echo crc32('htmlhptaccuin');"
121189226
perl -MString::CRC32 -e 'print crc32("htmlhptaccuin")'
121189226

#This doesn't:
php -r "echo crc32('html:hp_taccuino');"
-1565398511
perl -MString::CRC32 -e 'print crc32("html:hp_taccuino")'
2729568785

Expected result:
----------------
I expect to have the same CRC32 hash everywhere, so I 
expect to get 2729568785 in the above example.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-23 19:03 UTC] derick@php.net
PHP only has signed integers, use:
php -r "printf('%u', crc32('html:hp_taccuino'));"

and you see it works fine.
 [2005-03-23 19:10 UTC] alex at primafila dot net
Thank you a lot. Not only you were so fast, but you're 
also right :-)
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Sep 21 19:01:25 2018 UTC