1. 程式人生 > >python crc計算器

python crc計算器

取樣的是python 的crcmod模組,安裝就不說了,直接pip就好了。

import crcmod.predefined
from binascii import unhexlify

crc16_xmodem = crcmod.mkCrcFun(0x11021, rev=False, initCrc=0x0000, xorOut=0x0000)

s0 = 'a731986b1500087f9206e82e3829fe8bcffed5555efd00a100980000010000000100000009010013bb1d001e287107009b3000000300000088330000f427500077026309'

print hex(crc16_xmodem(unhexlify(s0)))

s0 = '1122334455'

print "crc16_xmodem:",hex(crc16_xmodem(unhexlify(s0)))

crc16_ibm = crcmod.mkCrcFun(0x18005, rev=True, initCrc=0x0000, xorOut=0x0000)
print "crc16_ibm",hex(crc16_ibm(unhexlify(s0)))


s = unhexlify('a731986b1500087f9206e82e3829fe8bcffed5555efd00a100980000010000000100000009010013bb1d001e287107009b3000000300000088330000f427500077026309')

print hex(crc16_xmodem(s))

crc16 = crcmod.predefined.Crc('xmodem')
crc16.update(s)
print crc16.hexdigest()