0

CRC32 comparisons in Python:

>>> zlib.crc32(np.int64(1)) == zlib.crc32(np.int32(1))
False

>>> np.int64(1) == np.int32(1)
True

>>> zlib.crc32(np.int64(1))
2844319735

>>> zlib.crc32(np.int32(1))
2583214201

The polynomial expression of 1, regardless of its int64 or int32 data type, should be the same and yet their CRC32 results are different. I've tried many other numbers than 1 and the CRC32 of the int64 and int32 results still won't match.

Any help in clearing up this incredibly confusing issue would be very much appreciated.

neil
  • 5
  • 2
  • 3
    CRC runs over byte streams, not numbers. One is (probably) doing CRC32(1, 0, 0, 0, 0, 0, 0, 0) and the other is doing CRC32(1, 0, 0, 0) presuming Little Endian. – Max Sep 02 '20 at 18:36
  • I see. Twisting my question a bit, assuming instead if my system is Big Endian, then zlib.crc32(np.int64(1)) == zlib.crc32(np.int32(1)) will return True, is this correct? – neil Sep 03 '20 at 01:58
  • No. CRC32 is length sensitive. You can feed it as many zeros as you want and get (generally) different results, at least until you start hitting collisions. – Max Sep 03 '20 at 16:53

1 Answers1

2

cbc32 works on bytes.

int32 is 4 bytes, 1 is 01 00 00 00

int64 is 8 bytes, 1 is 01 00 00 00 00 00 00 00

>>> zlib.crc32(np.int64(1)) == zlib.crc32(b''.join([np.int32(1), np.int32(0)]))
True
Cyril Jouve
  • 990
  • 5
  • 15