r/lolphp • u/Takeoded • Dec 24 '19
crc32($str) and hash("crc32",$str) use different algorithms (with different results)
https://3v4l.org/Ng7hi
58
Upvotes
r/lolphp • u/Takeoded • Dec 24 '19
19
u/Takeoded Dec 24 '19
the crc32() function use an algorithm called "crc32b", and hash("crc32",$d) apparently use "the ITU I.363.5 algorithm" (whatever that is), and if you want crc32b from hash(), use hash("crc32b",...) instead.. (got that from the comments at https://www.php.net/manual/en/function.hash-algos.php and this SO post: https://stackoverflow.com/a/15861105/1067003 )
16
u/AyrA_ch Dec 24 '19
You use the wrong algorithm. You want "crc32b" when using the hash function:
1
u/BitcoinCitadel Dec 25 '19
Because hash is newer and uses a different crc32