CRC32 vs. CRC32B

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, 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!")));'

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!")))));'

That's all folks.


2 Kommentare. Schreib was dazu

  1. Great! Thanks a lot :)

  2. Alf

    You analysis is not correct! (pls improve)
    There is a correct answer (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.

Schreib was dazu

Die folgenden HTML-Tags sind erlaubt:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>