-1

I need to calculate CRC-32/JAMCRC decimal number from a string in Python 3. How can I do it? For example, this webpage does it: https://www.crccalc.com/ - for 'hello-world' it prints 1311505828. I would like to have script which does exactly the same calculation. I've already tried to use zlib.crc32 and binascii.crc32 but their results for 'hello-world' is 2983461467.

Marek
  • 53
  • 1
  • 7

1 Answers1

0

To compute the CRC-32/JAMCRC you can simply perform the bitwise-not of the standard CRC-32 (in your case, the CRC-32 of 'hello-world' is 2983461467). But you can't simply use the ~ operator, because it works with signed integers (see this answer). Instead, you first need a subtraction:

import zlib
x = b'hello-world'
crc32_jamcrc = int("0b"+"1"*32, 2) - zlib.crc32(x) # 1311505828
Riccardo Bucco
  • 13,980
  • 4
  • 22
  • 50