on 6d45ede help sign in
160 lines 2.9 kB history raw
1---
2navhome: /docs
3---
6# 2e: insecure hashing
7### `++fnv`
9Hashes an atom with the 32-bit FNV non-cryptographic hash algorithm.
10Multiplies `a` by the prime number 16,777,619 and then takes the block
11of size 5 off the product's end, producing an atom.
13Accepts
14-------
16`a` is an atom.
18Produces
19--------
21An atom.
24Source
25------
27 ++ fnv |=(a/@ (end 5 1 (mul 16.777.619 a))) :: FNV scrambler
29Examples
30--------
32 > (fnv 10.000)
33 272.465.456
34 > (fnv 10.001)
35 289.243.075
36 > (fnv 1)
37 16.777.619
41***
42### `++mug`
44Hashes `a` with the 31-bit nonzero FNV-1a non-cryptographic hash
45algorithm, producing an atom.
47Accepts
48-------
50A is a noun.
52Produces
53--------
55An atom.
57Source
58------
60 ++ mug :: 31bit nonzero FNV1a
61 ~/ %mug
62 |= a/*
63 ?^ a
64 =+ b=[p=$(a -.a) q=$(a +.a)]
65 |- ^- @
66 =+ c=(fnv (mix p.b (fnv q.b)))
67 =+ d=(mix (rsh 0 31 c) (end 0 31 c))
68 ?. =(0 c) c
69 $(q.b +(q.b))
70 =+ b=2.166.136.261
71 |- ^- @
72 =+ c=b
73 =+ [d=0 e=(met 3 a)]
74 |- ^- @
75 ?: =(d e)
76 =+ f=(mix (rsh 0 31 c) (end 0 31 c))
77 ?. =(0 f) f
78 ^$(b +(b))
79 $(c (fnv (mix c (cut 3 [d 1] a))), d +(d))
82Examples
83--------
85 > (mug 10.000)
86 178.152.889
87 > (mug 10.001)
88 714.838.017
89 > (mug 1)
90 67.918.732
91 > (mug (some 10))
92 1.872.403.737
93 > (mug (limo [1 2 3 4 5 ~]))
94 1.067.931.605
98***
99### `++mum`
101XX document
103Accepts
104-------
106Produces
107--------
109Source
110------
112 ++ mum :: mug with murmur3
113 ~/ %mum
114 |= a/*
115 |^ (trim ?@(a a (mix $(a -.a) (mix 0x7fff.ffff $(a +.a)))))
116 ++ spec :: standard murmur3
117 |= {syd/@ key/@}
118 ?> (lte (met 5 syd) 1)
119 =+ ^= row
120 |= {a/@ b/@}
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)))
123 =+ len=(met 5 key)
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))
130 ^= goc
131 =+ [inx=0 goc=syd]
132 |- ^- @
133 ?: =(inx len) goc
134 =+ kop=(cut 5 [inx 1] key)
135 =. kop (mow kop 0xcc9e.2d51)
136 =. kop (row 15 kop)
137 =. kop (mow kop 0x1b87.3593)
138 =. goc (mix kop goc)
139 =. goc (row 13 goc)
140 =. goc (end 5 1 (add 0xe654.6b64 (mul 5 goc)))
141 $(inx +(inx))
144Examples
145--------
147 > (mum 10.000)
148 1.232.632.901
149 > (mum 10.001)
150 658.093.079
151 > (mum 1)
152 818.387.364
153 > (mum (some 10))
154 1.177.215.703
155 > (mum ~[1 2 3 4 5])
156 1.517.902.092
160***