Dieser Post wurde aus meiner alten WordPress-Installation importiert. Sollte es Darstellungsprobleme, falsche Links oder fehlende Bilder geben, bitte einfach hier einen Kommentar hinterlassen. Danke.
Someone asked me about a CRC32B checksum today. No problem, there is CPAN and a common checksum like CRC should be very easy, there must be a module (or two or three or so) on CPAN, task done, next one. Stop. There are two modules for CRC32: Digest::CRC32 and String::CRC32 but really nothing for CRC32B.
Google didn't find anything useful at all until I stumbled on PHP.net, home of the famous HTML preprocessor some people still call a "programming language". It looks like CRC32B doesn't exist at all and has been invented by PHP, official versions seems to be CRC32C and CRC32K.
I found a web-based CRC32B calculator and tried to hash the same string with Perl:
PHP/Web: 1b851995
perl -MString::CRC32 -le 'print unpack("h*",pack("L",crc32("Hello world!")));'
599158b1
Nice, isn't it? The great CRC32B is nothing more than a reversed standard CRC32, add a reverse and you get the same result as PHP:
perl -MString::CRC32 -le 'print scalar(reverse(unpack("h*",pack("L",crc32("Hello world!")))));'
1b851995
That's all folks.
2 Kommentare. Schreib was dazu-
Roman
11.10.2012 8:47
Antworten
-
Alf
5.05.2017 9:48
Antworten
Great! Thanks a lot :)
You analysis is not correct! (pls improve)
There is a correct answer http://www.php.net/manual/en/function.hash-file.php#104836 (also 5 years old)
There are >10 official ways to calculate CRC32 and >20 with MSB/LSB,
CRC32b is just an inveted name by PHP (you 're right there) but only to provide 2ways of CRC calculation.
As you noticed is PHP-CRC32b compatible with perl-CRC32 (unaware of MSB/LSB),
but PHP-CRC32 is not.