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.
Asked
Active
Viewed 669 times
1 Answers
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
-
Is it possible to calculate JAMCRC without converting the string to bytes? – Marek Dec 06 '19 at 16:51