why
from zlib import crc32
import numpy as np
x = crc32(np.int64(0))
print(x)
the output is 1696784233, how is this possible since I thought CRC gives the reminder of some generative polynomial with the parameter but since the parameter is 0 how is the output not 0?
This is because the zlib version of CRC-32 is specifically designed to handle leading zeroes (as well as any trailing zeroes inserted after the checksum). According to Wikipedia:
The shift register may be initialized with ones instead of zeroes. This is equivalent to inverting the first n n bits of the message before feeding them into the algorithm.
The reason this method is used is because an unmodified CRC does not distinguish between two messages which differ only in the number of leading zeroes, because leading zeroes do not affect the value of M(x). When this inversion is done, the CRC does distinguish between such messages.
The CRC may be inverted before being appended to the message stream. While an unmodified CRC distinguishes between messages M(x) with different numbers of trailing zeroes, it does not detect trailing zeroes appended after the CRC remainder itself. This is because all valid codewords are multiples of G(x), so x times that codeword is also a multiple. (In fact, this is precisely why the first variant described above works.)
You can manually undo that to see that zlib.crc32(numpy.int64(0), 0xFF_FF_FF_FF) == 0xFF_FF_FF_FF
, and in fact zlib.crc32(bytes(i), 0xFF_FF_FF_FF) == 0xFF_FF_FF_FF
for any natural number i
.