Marek
Marek

Reputation: 53

Python - calculate JAMCRC from string without converting it to bytes

I'm learning Python 3 and my question is: it possible to calculate JAMCRC from a string without converting the string to bytes (without encoding it)? I'm currently using this code:

import zlib

result = int('0b'+'1'*32,2) - zlib.crc32('ł'.encode('cp852'))
print(result)

but zlib requires a byte-like object as a parameter. I'm comparing the JAMCRC results with a Windows third-party program, and string encoding is causing different results. The results are equal if a use standard ASCII characters, but results are different when I use Polish letters. I want my script to always calculate JAMCRC result equal to this Windows program. For example, when I set the encoding to 8859 the results for letter ó from both programs (my script and third-party Windows program) are equal; but I cannot do it with letter ł because ł is not supported by 8859 encoding; I can change encoding to cp852 but the CRC result is different from the other program. The results was always equal when I used only standard ASCII characters and utf-8 encoding and results started to be different when I started to use Polish characters. How can I do it?

Upvotes: 1

Views: 198

Answers (1)

Marek
Marek

Reputation: 53

Later I've learned that the answer is: No - CRC works on bytes. Besides, different results were caused by different encoding.

Upvotes: 1

Related Questions