The SipHash produces a hash function which is optimized for speed on short messages. It is typically used in networking application, and is simpler than cryptographic hahing methods. It produces a 64-bit output, and can produce Gigahashes/sec. It is not quite as fast as xxHash, but is considerably faster than MD5 and SHA-1.
Siphash, Farm and djb2Sample runA sample run is: ======Siphash========= Key: 0123456789ABCDE0 Message: hello Hash: 10442178880121868220 ======Farm Hash========= Farmhash: 13009744463427800296 ======Murmur Hash========= Murmur3: 11548395115745546715 Murmur3: 213030289162235495270783145757721615258 ======xxHash========= xxHash32: fb0077f9 xxHash64: 26c7827d889f6da3 ======djb2 Hash========= DJB2: 0xf923099L ======FNV-1a Hash========= FNV-1: 2879634789696118705735610293694015385900839271 FNV-1: 23615531076550004469577376377959424885116481126984737282095593755520035349976263 FNV-1a: 2879634757790805244413300996931090322359790763 FNV-1a: 23615531076550004533854898275474062960111728987064870418154029787321558796778763 ======Loselose Hash========= Loselose: 532 In this case we have a hash of "e786fca9472ab083e5bb84c55fe6b581" which is 32 hex characters, and is thus 128-bits (16 bytes). CodeAn outline of the code is: import siphash import farmhash import sys def hash_djb2(s): hash = 5381 for x in s: hash = (( hash << 5) + hash) + ord(x) return hash & 0xFFFFFFFF def fnv1_32(string, seed=0): FNV_prime = 16777619 offset_basis = 2166136261 #FNV-1a Hash Function hash = offset_basis + seed for char in string: hash = hash * FNV_prime hash = hash ^ ord(char) return hash def fnv1a_32(string, seed=0): FNV_prime = 16777619 offset_basis = 2166136261 hash = offset_basis + seed for char in string: hash = hash ^ ord(char) hash = hash * FNV_prime return hash def fnv1_64(string, seed=0): FNV_prime = 1099511628211 offset_basis = 14695981039346656037 #FNV-1a Hash Function hash = offset_basis + seed for char in string: hash = hash * FNV_prime hash = hash ^ ord(char) return hash def fnv1a_64(string, seed=0): FNV_prime = 1099511628211 offset_basis = 14695981039346656037 hash = offset_basis + seed for char in string: hash = hash ^ ord(char) hash = hash * FNV_prime return hash def loselose(s): hsh = 0 for c in s: hsh += ord(c) return hsh str1="hello" key = '0123456789ABCDE' key=key.ljust(16, '0') sip = siphash.SipHash_2_4(key.encode()) sip.update(str1.encode()) print("======Siphash=========") print("Key:\t\t",key) print("Message:\t",str1) print("Hash:\t\t",sip.hash()) print("\n======Farm Hash=========") print("Farmhash:\t",farmhash.hash64(str1)) print("\n======Murmur Hash=========") import smhasher print("Murmur3:\t",smhasher.murmur3_x86_64(str1)) print("Murmur3:\t",smhasher.murmur3_x86_128(str1)) print("\n======xxHash=========") import xxhash print("xxHash32:\t",xxhash.xxh32(str1).hexdigest()) print("xxHash64:\t",xxhash.xxh64(str1).hexdigest()) print("\n======djb2 Hash=========") print("\n======FNV-1a Hash=========") print("FNV-1:\t",fnv1_32(str1)) print("FNV-1:\t",fnv1_64(str1)) print("FNV-1a:\t",fnv1a_32(str1)) print("FNV-1a:\t",fnv1a_64(str1)) print("\n======Loselose Hash=========") print("Loselose:\t",loselose(str1)) print("DJB2:\t\t",hex(hash_djb2(str1))) The performance of the Siphash is fairly good, but no where near as fast as xxHash64 Cityhash64, Spooky and Farm64: Ref: [here] |