Skip to content

Commit

Permalink
Merge pull request #49 from jhalon/brc4_joaat
Browse files Browse the repository at this point in the history
Add JOAAT Hash Algorithm used by BRC4
  • Loading branch information
herrcore authored Dec 6, 2023
2 parents fef3215 + 2c3bdad commit d568247
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions algorithms/brc4_joaat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python

DESCRIPTION = "Jenkins One At A Time (JOAAT) Hashing Algorithm Used by BRC4"
# Type can be either 'unsigned_int' (32bit) or 'unsigned_long' (64bit)
TYPE = 'unsigned_int'
# Test must match the exact hash of the string 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
TEST_1 = 4059668722


def hash(data):
val = 0
for c in data:
v1 = c + val
v2 = (1025 * v1) & 0xffffffff
v3 = v2 >> 6
val = v2 ^ v3

val = (val + val * 8) & 0xffffffff
r1 = val >> 11
r2 = val ^ r1
result = r2 * 32769 & 0xffffffff

return result

0 comments on commit d568247

Please sign in to comment.