on 140ac0e help sign in
155 lines 2.9 kB history raw
1# 2e: insecure hashing
2### `++fnv`
4Hashes an atom with the 32-bit FNV non-cryptographic hash algorithm.
5Multiplies `a` by the prime number 16,777,619 and then takes the block
6of size 5 off the product's end, producing an atom.
8Accepts
9-------
11`a` is an atom.
13Produces
14--------
16An atom.
19Source
20------
22 ++ fnv |=(a/@ (end 5 1 (mul 16.777.619 a))) :: FNV scrambler
24Examples
25--------
27 > (fnv 10.000)
28 272.465.456
29 > (fnv 10.001)
30 289.243.075
31 > (fnv 1)
32 16.777.619
36***
37### `++mug`
39Hashes `a` with the 31-bit nonzero FNV-1a non-cryptographic hash
40algorithm, producing an atom.
42Accepts
43-------
45A is a noun.
47Produces
48--------
50An atom.
52Source
53------
55 ++ mug :: 31bit nonzero FNV1a
56 ~/ %mug
57 |= a/*
58 ?^ a
59 =+ b=[p=$(a -.a) q=$(a +.a)]
60 |- ^- @
61 =+ c=(fnv (mix p.b (fnv q.b)))
62 =+ d=(mix (rsh 0 31 c) (end 0 31 c))
63 ?. =(0 c) c
64 $(q.b +(q.b))
65 =+ b=2.166.136.261
66 |- ^- @
67 =+ c=b
68 =+ [d=0 e=(met 3 a)]
69 |- ^- @
70 ?: =(d e)
71 =+ f=(mix (rsh 0 31 c) (end 0 31 c))
72 ?. =(0 f) f
73 ^$(b +(b))
74 $(c (fnv (mix c (cut 3 [d 1] a))), d +(d))
77Examples
78--------
80 > (mug 10.000)
81 178.152.889
82 > (mug 10.001)
83 714.838.017
84 > (mug 1)
85 67.918.732
86 > (mug (some 10))
87 1.872.403.737
88 > (mug (limo [1 2 3 4 5 ~]))
89 1.067.931.605
93***
94### `++mum`
96XX document
98Accepts
99-------
101Produces
102--------
104Source
105------
107 ++ mum :: mug with murmur3
108 ~/ %mum
109 |= a/*
110 |^ (trim ?@(a a (mix $(a -.a) (mix 0x7fff.ffff $(a +.a)))))
111 ++ spec :: standard murmur3
112 |= {syd/@ key/@}
113 ?> (lte (met 5 syd) 1)
114 =+ ^= row
115 |= {a/@ b/@}
116 (con (end 5 1 (lsh 0 a b)) (rsh 0 (sub 32 a) b))
117 =+ mow=|=({a/@ b/@} (end 5 1 (mul a b)))
118 =+ len=(met 5 key)
119 =- =. goc (mix goc len)
120 =. goc (mix goc (rsh 4 1 goc))
121 =. goc (mow goc 0x85eb.ca6b)
122 =. goc (mix goc (rsh 0 13 goc))
123 =. goc (mow goc 0xc2b2.ae35)
124 (mix goc (rsh 4 1 goc))
125 ^= goc
126 =+ [inx=0 goc=syd]
127 |- ^- @
128 ?: =(inx len) goc
129 =+ kop=(cut 5 [inx 1] key)
130 =. kop (mow kop 0xcc9e.2d51)
131 =. kop (row 15 kop)
132 =. kop (mow kop 0x1b87.3593)
133 =. goc (mix kop goc)
134 =. goc (row 13 goc)
135 =. goc (end 5 1 (add 0xe654.6b64 (mul 5 goc)))
136 $(inx +(inx))
139Examples
140--------
142 > (mum 10.000)
143 1.232.632.901
144 > (mum 10.001)
145 658.093.079
146 > (mum 1)
147 818.387.364
148 > (mum (some 10))
149 1.177.215.703
150 > (mum ~[1 2 3 4 5])
151 1.517.902.092
155***