Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRC-32 oddity in PHP

Tags:

php

hash

crc

crc32

Is there some specific reason why crc32($data) yields a completely different hash than hash("crc32", $data) in PHP?

Consider this code snippet (also posted online at http://ideone.com/eqbin4):

<?php
$data = "message";
echo(sprintf("%08x", crc32($data)) . "\n");
echo(hash("crc32", $data) . "\n");
?>

Output:

b6bd307f
c048b5b8

What am I getting wrong here, or is this just a PHP curiosity, using different CRC-32 computation methods for the same type of hash?

like image 538
emkey08 Avatar asked Jul 20 '26 14:07

emkey08


1 Answers

Looks like thecrc32($d) function is equalent to the hash("crc32b", $d) call, not the hash("crc32", $d).

like image 54
Jite Avatar answered Jul 22 '26 03:07

Jite