@@ -6,33 +6,32 @@ navhome: /docs/
6# 2e: insecure hashing
6# 2e: insecure hashing
9−Hashes an atom with the 32-bit FNV non-cryptographic hash algorithm.
9+FNV scrambler
10−Multiplies `a` by the prime number 16,777,619 and then takes the block
11−of size 5 off the product's end, producing an atom.
11+Hashes an atom with the 32-bit FNV non-cryptographic hash algorithm. Multiplies
12+`a` by the prime number 16,777,619 and then takes the [block](../2c.md) of size
13+5 off the product's end, producing an atom.
13−Accepts
15+#### Accepts
16`a` is an atom.
17`a` is an atom.
18−Produces
19+#### Produces
27− ++ fnv |=(a/@ (end 5 1 (mul 16.777.619 a))) :: FNV scrambler
25+ ++ fnv |=(a=@ (end 5 1 (mul 16.777.619 a)))
29−Examples
27+#### Examples
32 > (fnv 10.000)
29 > (fnv 10.000)
33 272.465.456
30 272.465.456
34 > (fnv 10.001)
32 > (fnv 10.001)
35 289.243.075
33 289.243.075
37 16.777.619
36 16.777.619
@@ -41,31 +40,30 @@ Examples
42### `++mug`
41### `++mug`
44−Hashes `a` with the 31-bit nonzero FNV-1a non-cryptographic hash
45+Hashes `a` with the 31-bit nonzero FNV-1a non-cryptographic hash algorithm,
45−algorithm, producing an atom.
46+producing an atom.
47−Accepts
48+#### Accepts
50−A is a noun.
50+`a` is a noun.
52−Produces
52+#### Produces
60− ++ mug :: 31bit nonzero FNV1a
58+ ++ mug
64 =+ b=[p=$(a -.a) q=$(a +.a)]
62 =+ b=[p=$(a -.a) q=$(a +.a)]
66 =+ c=(fnv (mix p.b (fnv q.b)))
64 =+ c=(fnv (mix p.b (fnv q.b)))
67 =+ d=(mix (rsh 0 31 c) (end 0 31 c))
65 =+ d=(mix (rsh 0 31 c) (end 0 31 c))
68− ?. =(0 c) c
66+ ?. =(0 d) d
69 $(q.b +(q.b))
67 $(q.b +(q.b))
70 =+ b=2.166.136.261
68 =+ b=2.166.136.261
@@ -79,81 +77,188 @@ Source
79 $(c (fnv (mix c (cut 3 [d 1] a))), d +(d))
77 $(c (fnv (mix c (cut 3 [d 1] a))), d +(d))
82−Examples
80+#### Examples
85 > (mug 10.000)
82 > (mug 10.000)
86 178.152.889
83 178.152.889
87 > (mug 10.001)
85 > (mug 10.001)
88 714.838.017
86 714.838.017
90 67.918.732
89 67.918.732
91 > (mug (some 10))
91 > (mug (some 10))
92 1.872.403.737
92 1.872.403.737
93− > (mug (limo [1 2 3 4 5 ~]))
94+ > (mug [1 2 3 4 5 ~])
94 1.067.931.605
95 1.067.931.605
104+Implementation of the 32-bit
105+[MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash#Algorithm)
106+non-cryptographic hash algorithm. Takes `a` as the seed, `b` as the key length
107+in [blocks](../2c) of size 3, and `c` as the key, producing an atom.
125+ |= [syd=@ len=@ key=@]
126+ ?> &((lte (met 5 syd) 1) (lte (met 0 len) 31))
127+ =/ pad (sub len (met 3 key))
128+ =/ data (weld (rip 3 key) (reap pad 0))
129+ =/ nblocks (div len 4) :: intentionally off-by-one
131+ =+ [c1=0xcc9e.2d51 c2=0x1b87.3593]
132+ =/ blocks (rip 5 key)
135+ ?: =(0 i) hi :: negative array index
136+ =/ k1 (snag (sub nblocks i) blocks)
137+ =. k1 (sit (mul k1 c1))
139+ =. k1 (sit (mul k1 c2))
142+ =. hi (sum (sit (mul hi 5)) 0xe654.6b64)
144+ =/ tail (slag (mul 4 nblocks) data)
148+ ?+ tlen h1 :: fallthrough switch
149+ $3 =. k1 (mix k1 (lsh 0 16 (snag 2 tail)))
150+ =. k1 (mix k1 (lsh 0 8 (snag 1 tail)))
151+ =. k1 (mix k1 (snag 0 tail))
152+ =. k1 (sit (mul k1 c1))
154+ =. k1 (sit (mul k1 c2))
156+ $2 =. k1 (mix k1 (lsh 0 8 (snag 1 tail)))
157+ =. k1 (mix k1 (snag 0 tail))
158+ =. k1 (sit (mul k1 c1))
160+ =. k1 (sit (mul k1 c2))
162+ $1 =. k1 (mix k1 (snag 0 tail))
163+ =. k1 (sit (mul k1 c1))
165+ =. k1 (sit (mul k1 c2))
172+ =. h (mix h (rsh 0 16 h))
173+ =. h (sit (mul h 0x85eb.ca6b))
174+ =. h (mix h (rsh 0 13 h))
175+ =. h (sit (mul h 0xc2b2.ae35))
176+ =. h (mix h (rsh 0 16 h))
201+ > (muk 6 15 'jerry')
204+ > =e (cut 3 [0 2] eny) :: `eny` is 512 bits of entropy (a random number).
99### `++mum`
214### `++mum`
101−XX document
216+31-bit MurmurHash3 scrambler
103−Accepts
218+Hashes `a` with the 31-bit MurmurHash3 non-cryptographic hash algorithm,
104−-------
219+producing an atom.
106−Produces
221+#### Accepts
109−Source
223+`a` is a noun.
112− ++ mum :: mug with murmur3
225+#### Produces
115 |^ (trim ?@(a a (mix $(a -.a) (mix 0x7fff.ffff $(a +.a)))))
234 |^ (trim ?@(a a (mix $(a -.a) (mix 0x7fff.ffff $(a +.a)))))
116− ++ spec :: standard murmur3
235+ ++ trim
117− |= {syd/@ key/@}
236+ |= key=@
118− ?> (lte (met 5 syd) 1)
237+ =+ syd=0xcafe.babe
121− (con (end 5 1 (lsh 0 a b)) (rsh 0 (sub 32 a) b))
122− =+ mow=|=({a/@ b/@} (end 5 1 (mul a b)))
124− =- =. goc (mix goc len)
125− =. goc (mix goc (rsh 4 1 goc))
126− =. goc (mow goc 0x85eb.ca6b)
127− =. goc (mix goc (rsh 0 13 goc))
128− =. goc (mow goc 0xc2b2.ae35)
129− (mix goc (rsh 4 1 goc))
133− ?: =(inx len) goc
239+ =+ haz=(muk syd (met 3 key) key)
134− =+ kop=(cut 5 [inx 1] key)
240+ =+ ham=(mix (rsh 0 31 haz) (end 0 31 haz))
135− =. kop (mow kop 0xcc9e.2d51)
241+ ?.(=(0 ham) ham $(syd +(syd)))
137− =. kop (mow kop 0x1b87.3593)
138− =. goc (mix kop goc)
140− =. goc (end 5 1 (add 0xe654.6b64 (mul 5 goc)))
144−Examples
243+#### Examples
147 > (mum 10.000)
245 > (mum 10.000)
148− 1.232.632.901
246+ 795.713.195
149 > (mum 10.001)
248 > (mum 10.001)
150− 658.093.079
249+ 420.521.697
151 > (mum 1)
254 > (mum 1)
152− 818.387.364
255+ 1.901.865.568
153 > (mum (some 10))
257 > (mum (some 10))
154− 1.177.215.703
258+ 2.099.076.946
155− > (mum ~[1 2 3 4 5])
260+ > (mum [1 2 3 4 5 ~])
156− 1.517.902.092
261+ 1.719.833.228