Created
October 21, 2013 03:38
-
-
Save sugiana/7078312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Reference: | |
http://depa.usst.edu.cn/chenjq/www2/SDesign/JavaScript/CRCcalculation.htm | |
Input: | |
CRC Order: 32 | |
CRC Polynom: 4C11DB7 | |
Data Input: | |
Type: Hex | |
Value: 0403020108070605 | |
Result: | |
CRC (hex): CA10A083 | |
Install crcmod module first: | |
pip install crcmod | |
""" | |
import crcmod | |
import binascii | |
# Create function | |
func = crcmod.mkCrcFun(poly=0x104C11DB7, initCrc=0, rev=False, xorOut=0x0) | |
# Get input | |
raw = '\x04\x03\x02\x01\x08\x07\x06\x05' | |
print([raw]) | |
print([binascii.hexlify(raw)]) | |
# Calculate CRC | |
crc_result = func(raw) | |
print(hex(crc_result)) | |
# Is match ? | |
crc_check = 0xca10a083 | |
if crc_check == crc_result: | |
print('CRC match.') | |
else: | |
print('CRC mismatch.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment