forked from luc10/zykgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cocktail.go
109 lines (100 loc) · 3.35 KB
/
cocktail.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package zykgen
type Cocktail int
type CocktailFunction func(needle int32, base int) byte
const (
Mojito Cocktail = iota
Negroni
Cosmopolitan
)
var cocktails = map[Cocktail]CocktailFunction{
Mojito: mojito,
Negroni: negroni,
Cosmopolitan: cosmopolitan,
}
var ingredients = map[Cocktail]struct {
haystack []byte
charset []byte
}{
Mojito: {
haystack: []byte{
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'i', 'l', 'o', 's', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 't', 'u', 'v',
'w', 'x', 'y', 'z', '1', '2', '5', '6', '9', '0', 'I', 'O', 'S', 'Z', '3', '4',
'7', '8', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P',
'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', '1', '2', '5', '6', '9', '0', 'I', 'O',
'S', 'V', 'W', 'Z', '3', '4', '7', '8', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y',
},
charset: []byte{
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 't',
'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '5', '6', '9', '0', 'I', 'O', 'S', 'Z',
'3', '4', '7', '8', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', '1', '2', '5', '6', '9', '0',
'I', 'O', 'S', 'V', 'W', 'Z', '3', '4', '7', '8', 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y',
},
},
Negroni: {
haystack: []byte{
'1', '2', '5', '6', '9', '0', 'I', 'O', 'S', 'Z', '3', '4', '7', '8', 'A', 'B',
'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U',
'V', 'W', 'X', 'Y', '1', '2', '5', '6', '9', '0', 'I', 'O', 'S', 'V', 'W', 'Z',
'3', '4', '7', '8', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y',
},
charset: []byte{
'3', '4', '7', '8', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', '1', '2', '5', '6', '9', '0',
'I', 'O', 'S', 'V', 'W', 'Z', '3', '4', '7', '8', 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y',
},
},
Cosmopolitan: {
haystack: []byte{
'1', '2', '5', '6', '9', '0', 'I', 'O', 'S', 'V', 'W', 'Z', '3', '4', '7', '8',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'K', 'L', 'J', 'M', 'N', 'P', 'Q', 'R',
'T', 'U', 'X', 'Y',
},
charset: []byte{
'3', '4', '7', '8', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y',
},
},
}
func pick(haystack, charset []byte, needle byte, base, max, v int) byte {
for i := 0; i < max; i++ {
if haystack[i] == byte(needle) {
return charset[bobbidi(base+i, v)]
}
}
return byte(needle)
}
// Mojito method requires needle to be transformed before
// being passed to pick function
func mojito(needle int32, base int) byte {
return pick(
ingredients[Mojito].haystack,
ingredients[Mojito].charset,
transform(needle, -65, 32),
base,
14, 22,
)
}
func negroni(needle int32, base int) byte {
return pick(
ingredients[Negroni].haystack,
ingredients[Negroni].charset,
byte(needle),
base,
10, 26,
)
}
func cosmopolitan(needle int32, base int) byte {
return pick(
ingredients[Cosmopolitan].haystack,
ingredients[Cosmopolitan].charset,
byte(needle),
base,
12, 24,
)
}