[Bio] / FigKernelScripts / crc64.py Repository:
ViewVC logotype

Annotation of /FigKernelScripts/crc64.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : mkubal 1.1 import sys
2 :     # Initialisation
3 :     # 32 first bits of generator polynomial for CRC64
4 :     # the 32 lower bits are assumed to be zero
5 :    
6 :     POLY64REVh = 0xd8000000L
7 :     CRCTableh = [0] * 256
8 :     CRCTablel = [0] * 256
9 :     isInitialized = False
10 :    
11 :     def CRC64(aString):
12 :     global isInitialized
13 :     crcl = 0
14 :     crch = 0
15 :     if (isInitialized is not True):
16 :     isInitialized = True
17 :     for i in xrange(256):
18 :     partl = i
19 :     parth = 0L
20 :     for j in xrange(8):
21 :     rflag = partl & 1L
22 :     partl >>= 1L
23 :     if (parth & 1):
24 :     partl |= (1L << 31L)
25 :     parth >>= 1L
26 :     if rflag:
27 :     parth ^= POLY64REVh
28 :     CRCTableh[i] = parth;
29 :     CRCTablel[i] = partl;
30 :    
31 :     for item in aString:
32 :     shr = 0L
33 :     shr = (crch & 0xFF) << 24
34 :     temp1h = crch >> 8L
35 :     temp1l = (crcl >> 8L) | shr
36 :     tableindex = (crcl ^ ord(item)) & 0xFF
37 :    
38 :     crch = temp1h ^ CRCTableh[tableindex]
39 :     crcl = temp1l ^ CRCTablel[tableindex]
40 :     return (crch, crcl)
41 :    
42 :     def CRC64digest(aString):
43 :     return "%08X%08X" % (CRC64(aString))
44 :    
45 :     if __name__ == '__main__':
46 :    
47 :     id = sys.argv[1]
48 :     seq = sys.argv[2];
49 :     crc = CRC64digest(seq)
50 :     print id + "\t" + crc

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3