4371 shaares
Turns out PHP standard crc32
method is non-standard (while crc32b
is).
Here is how to implement it in Python:
def php_crc32(a):
'''
References:
- https://www.php.net/manual/en/function.hash-file.php#104836
- https://stackoverflow.com/a/50843127/636849
'''
crc = 0xffffffff
for x in a:
crc ^= x << 24;
for k in range(8):
crc = (crc << 1) ^ 0x04c11db7 if crc & 0x80000000 else crc << 1
crc = ~crc
crc &= 0xffffffff
# Convert from big endian to little endian:
return int.from_bytes(crc.to_bytes(4, 'big'), 'little')