|
Post by bblahq on Jul 18, 2022 19:50:43 GMT -5
Hello, I am looking for either: 1. FNV 64 high bit hash code for linux OR 2. A way to access the hash generator that comes with S4S from a command line interface.
I need to hash a lot of strings to FNV64 and it would be much faster to do so from a CLI where I can loop it. I have been searching Google and I am either really bad at searching or there isn't any info on the web for what I need.
Please respond if you know a way or have useful feedback
|
|
|
Post by andrew on Jul 19, 2022 0:44:03 GMT -5
Hi bblahq,
S4S has a few experimental CLI options but hash generation isn't an option yet. Since you are on linux, running S4S from the command line may be overkill for the task anyway. What language are you currently working with? If Python is an option for you, this function (adapted from the S4S Blender python scripts) could work:
from functools import reduce import struct
CONSTS = {32: (0x01000193, 0x811C9DC5), 64: (0x00000100000001B3, 0xCBF29CE484222325)}
def fnv(text='', size=64, offset=None, set_high_bit=False): base_number = 32 if size <= 32 else 64 prime, base_offset = CONSTS[base_number] base_mask = -(1 - (1 << base_number)) encoded = text.encode('utf-16be') h = reduce(lambda v, w: (v * prime ^ w) & base_mask, (struct.unpack('>H', encoded[i:i + 2])[0] for i in range(0, len(encoded), 2)), offset if offset else base_offset) if size != base_number: h = (h >> size) ^ (h & (base_mask >> (base_number - size))) if set_high_bit: h |= 1 << (base_number - 1) return h print(hex(fnv('Hello World'.lower(), size=64, set_high_bit=True)).upper()[2:])
Output:
FDCF62CDB1910E6F
|
|
|
Post by bblahq on Jul 20, 2022 6:24:17 GMT -5
Thank you Andrew. Python works perfectly. I will give the code a try.
|
|