How to calculate CRC32 with Python to match online results?

前端 未结 3 748
盖世英雄少女心
盖世英雄少女心 2020-12-13 19:19

I\'m trying to calculate/generate the CRC32 hash of some random strings using Python but they do not match the values I generate from online sources. Here is what I\'m doing

3条回答
  •  难免孤独
    2020-12-13 19:31

    zlib.crc32 documentation suggests using the following approach "to generate the same numeric value across all Python versions and platforms".

    import zlib
    hex(zlib.crc32(b'hello-world') & 0xffffffff)
    

    The result is 0xb1d4025b as expected.

提交回复
热议问题