-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from JANlittle/main
add algorithm or20_xor_rol19
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
|
||
DESCRIPTION = "OR 0x20 and XOR and ROL 19" | ||
TYPE = 'unsigned_int' | ||
TEST_1 = 0x186f3f38 | ||
|
||
|
||
ROTATE_BITMASK = { | ||
8: 0xff, | ||
16: 0xffff, | ||
32: 0xffffffff, | ||
64: 0xffffffffffffffff, | ||
} | ||
|
||
|
||
def rol(inVal, numShifts, dataSize=32): | ||
'''rotate left instruction emulation''' | ||
if numShifts == 0: | ||
return inVal | ||
if (numShifts < 0) or (numShifts > dataSize): | ||
raise ValueError('Bad numShifts') | ||
if (dataSize != 8) and (dataSize != 16) and (dataSize != 32) and (dataSize != 64): | ||
raise ValueError('Bad dataSize') | ||
bitMask = ROTATE_BITMASK[dataSize] | ||
return bitMask & ((inVal << numShifts) | (inVal >> (dataSize-numShifts))) | ||
|
||
|
||
def hash(data): | ||
val = 0xffffffff | ||
ors = 0 | ||
for i in data: | ||
ors = i | 32 | ||
val = ors ^ rol(val, 19, 32) | ||
return val |