Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRC32 checksum in Python with hex input

I'm wanting to calculate the CRC32 checksum of a string of hex values in python. I found zlib.crc32(data) and binascii.crc32(data), but all the examples I found using these functions have 'data' as a string ('hello' for example). I want to pass hex values in as data and find the checksum. I've tried setting data as a hex value (0x18329a7e for example) and I get a TypeError: must be string or buffer, not int. The function evaluates when I make the hex value a string ('0x18329a7e' for example), but I don't think it's evaluating the correct checksum. Any help would be appreciated. Thanks!

like image 608
dmranck Avatar asked Dec 13 '22 14:12

dmranck


1 Answers

I think you are looking for binascii.a2b_hex():

>>> binascii.crc32(binascii.a2b_hex('18329a7e'))
-1357533383
like image 131
Andrew Clark Avatar answered Jan 01 '23 01:01

Andrew Clark