# 2e: insecure hashing ### `++fnv` Hashes an atom with the 32-bit FNV non-cryptographic hash algorithm. Multiplies `a` by the prime number 16,777,619 and then takes the block of size 5 off the product's end, producing an atom. Accepts ------- `a` is an atom. Produces -------- An atom. Source ------ ++ fnv |=(a/@ (end 5 1 (mul 16.777.619 a))) :: FNV scrambler Examples -------- > (fnv 10.000) 272.465.456 > (fnv 10.001) 289.243.075 > (fnv 1) 16.777.619 *** ### `++mug` Hashes `a` with the 31-bit nonzero FNV-1a non-cryptographic hash algorithm, producing an atom. Accepts ------- A is a noun. Produces -------- An atom. Source ------ ++ mug :: 31bit nonzero FNV1a ~/ %mug |= a/* ?^ a =+ b=[p=$(a -.a) q=$(a +.a)] |- ^- @ =+ c=(fnv (mix p.b (fnv q.b))) =+ d=(mix (rsh 0 31 c) (end 0 31 c)) ?. =(0 c) c $(q.b +(q.b)) =+ b=2.166.136.261 |- ^- @ =+ c=b =+ [d=0 e=(met 3 a)] |- ^- @ ?: =(d e) =+ f=(mix (rsh 0 31 c) (end 0 31 c)) ?. =(0 f) f ^$(b +(b)) $(c (fnv (mix c (cut 3 [d 1] a))), d +(d)) Examples -------- > (mug 10.000) 178.152.889 > (mug 10.001) 714.838.017 > (mug 1) 67.918.732 > (mug (some 10)) 1.872.403.737 > (mug (limo [1 2 3 4 5 ~])) 1.067.931.605 *** ### `++mum` XX document Accepts ------- Produces -------- Source ------ ++ mum :: mug with murmur3 ~/ %mum |= a/* |^ (trim ?@(a a (mix $(a -.a) (mix 0x7fff.ffff $(a +.a))))) ++ spec :: standard murmur3 |= {syd/@ key/@} ?> (lte (met 5 syd) 1) =+ ^= row |= {a/@ b/@} (con (end 5 1 (lsh 0 a b)) (rsh 0 (sub 32 a) b)) =+ mow=|=({a/@ b/@} (end 5 1 (mul a b))) =+ len=(met 5 key) =- =. goc (mix goc len) =. goc (mix goc (rsh 4 1 goc)) =. goc (mow goc 0x85eb.ca6b) =. goc (mix goc (rsh 0 13 goc)) =. goc (mow goc 0xc2b2.ae35) (mix goc (rsh 4 1 goc)) ^= goc =+ [inx=0 goc=syd] |- ^- @ ?: =(inx len) goc =+ kop=(cut 5 [inx 1] key) =. kop (mow kop 0xcc9e.2d51) =. kop (row 15 kop) =. kop (mow kop 0x1b87.3593) =. goc (mix kop goc) =. goc (row 13 goc) =. goc (end 5 1 (add 0xe654.6b64 (mul 5 goc))) $(inx +(inx)) Examples -------- > (mum 10.000) 1.232.632.901 > (mum 10.001) 658.093.079 > (mum 1) 818.387.364 > (mum (some 10)) 1.177.215.703 > (mum ~[1 2 3 4 5]) 1.517.902.092 ***