From: Bernard Blackham Date: Fri, 25 Jun 2004 15:29:46 +0000 (+0000) Subject: Need this :) X-Git-Tag: IMPORT-FROM-UCCCVS~154 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b74ae9a47d39ad5b0c6d5d060ae030df107916b9;p=uccvend-vendserver.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)