[Biopython-dev] BioSQL upgrade [1 of 3]
Yves Bastide
Yves.Bastide at irisa.fr
Fri Nov 22 17:45:09 EST 2002
The first patch creates a Bio.crc, with crc32 and crc64 methods; I
needed a CRC64, and foud it clean to have it nicely with the usual CRC32 :-)
The crc64 code is a translation of the BioPerl one (I will only claim
the errors).
-------------- next part --------------
--- /dev/null 1970-01-01 01:00:00.000000000 +0100
+++ Bio/crc.py 2002-11-22 21:34:16.000000000 +0100
@@ -0,0 +1,32 @@
+# crc32 and crc64
+# crc64 is adapted from BioPerl
+
+from binascii import crc32
+
+_table_h = []
+
+def crc64(s):
+ crcl = 0
+ crch = 0
+ for c in s:
+ shr = (crch & 0xFF) << 24
+ temp1h = crch >> 8
+ temp1l = (crcl >> 8) | shr
+ idx = (crcl ^ ord(c)) & 0xFF
+ crch = temp1h ^ _table_h[idx]
+ crcl = temp1l
+
+ return "CRC-%08X%08X" % (crch, crcl)
+
+# Initialisation
+for i in range(256):
+ l = i
+ part_h = 0
+ for j in range(8):
+ rflag = l & 1
+ l >>= 1
+ if part_h & 1: l |= (1L << 31)
+ part_h >>= 1L
+ if rflag: part_h ^= 0xd8000000L
+ _table_h.append(part_h)
+
More information about the Biopython-dev
mailing list