From: Bernard Blackham Date: Fri, 25 Jun 2004 15:29:46 +0000 (+0000) Subject: Need this :) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=6f98a21b452a4ba4b0e574e362d2d8bd5712c89e;p=zanchey%2Fdispense2.git Need this :) --- diff --git a/sql-edition/servers/CRC.py b/sql-edition/servers/CRC.py new file mode 100644 index 0000000..512a7bd --- /dev/null +++ b/sql-edition/servers/CRC.py @@ -0,0 +1,16 @@ +crctab = [] +CRC16 = 0x1021 + +def do_crc(message, crc = 0): + for i in range(0,len(message)): + crc = ((crc << 8) ^ (crctab[(crc >> 8) ^ ord(message[i])])) & 0xffff + return crc + +# Generate crctab +for val in range(0,256): + crc = val << 8; + for i in range(0,8): + crc = crc << 1 + if (crc & 0x10000): + crc = crc ^ CRC16 + crctab.append(crc & 0xffff)