File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+
3
+ DESCRIPTION = "Graphical Proton string hashing algorithm"
4
+ TYPE = 'unsigned_int'
5
+ TEST_1 = "2194288283"
6
+
7
+ ROTATE_BITMASK = {
8
+ 8 : 0xff ,
9
+ 16 : 0xffff ,
10
+ 32 : 0xffffffff ,
11
+ 64 : 0xffffffffffffffff ,
12
+ }
13
+
14
+ def ror (inVal , numShifts , dataSize = 32 ):
15
+ '''rotate right instruction emulation'''
16
+ if numShifts == 0 :
17
+ return inVal
18
+ if (numShifts < 0 ) or (numShifts > dataSize ):
19
+ raise ValueError ('Bad numShifts' )
20
+ if (dataSize != 8 ) and (dataSize != 16 ) and (dataSize != 32 ) and (dataSize != 64 ):
21
+ raise ValueError ('Bad dataSize' )
22
+ bitMask = ROTATE_BITMASK [dataSize ]
23
+ return bitMask & ((inVal >> numShifts ) | (inVal << (dataSize - numShifts )))
24
+
25
+ def hash (data ):
26
+ out = 0x3ddfb511
27
+ for c in data :
28
+ temp = ror (out , 8 )
29
+ out = (ord (c ) + temp ) ^ out
30
+ return out
You can’t perform that action at this time.
0 commit comments