diff --git a/legendary/utils/rolling_hash.py b/legendary/utils/rolling_hash.py new file mode 100644 index 0000000..eb89034 --- /dev/null +++ b/legendary/utils/rolling_hash.py @@ -0,0 +1,25 @@ +# this is the rolling hash Epic uses, it appears to be a variation on CRC-64-ECMA + +hash_poly = 0xC96C5795D7870F42 +hash_table = [] + + +def _init(): + for i in range(256): + for _ in range(8): + if i & 1: + i >>= 1 + i ^= hash_poly + else: + i >>= 1 + hash_table.append(i) + + +def get_hash(data): + if not hash_table: + _init() + + h = 0 + for i in range(len(data)): + h = ((h << 1 | h >> 63) ^ hash_table[c.data[i]]) & 0xffffffffffffffff + return h