CRC16

Raymond L. Buvel levub137 at wi.rr.com
Fri Sep 23 19:02:33 EDT 2005


Tuvas wrote:
> Anyone know a module that does CRC16 for Python? I have an aplication
> that I need to run it, and am not having alot of sucess. I have a
> program in C that uses a CRC16 according to CCITT standards, but need
> to get a program that tests it with python as well. Thanks!
> 

Try this one

http://crcmod.sourceforge.net/

It will do what you want as long as you know what polynomial to use and
what type of algorithm.  I think you want the CCITT polynomial with a
bit-reverse algorithm.  If that is the case, the following will generate
the Python function you want (assumes you want to seed the CRC
calculation with the starting value of 0xffff).

import crcmod
crc16 = crcmod.mkCrcFun(0x11021, 0xffff, True)

Now compute the crc of a data string as

crc = crc16(data)



More information about the Python-list mailing list