-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbrutedict.go
78 lines (68 loc) · 1.33 KB
/
brutedict.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
package brutedict
type BruteDict struct {
isnum bool
islow bool
iscap bool
start int
end int
queue chan string
quit chan bool
running bool
}
func New(isnum, islow, iscap bool, start, end int) (bd *BruteDict) {
bd = &BruteDict{
isnum: isnum,
islow: islow,
iscap: iscap,
start: start,
end: end,
running: true,
queue: make(chan string),
quit: make(chan bool),
}
strnum := []byte("0123456789")
strlow := []byte("abcdefghijklmnopqrstuvwxyz")
strcap := []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
var str = make([]byte, 0)
if isnum {
str = append(str, strnum...)
}
if islow {
str = append(str, strlow...)
}
if iscap {
str = append(str, strcap...)
}
var b = make([]byte, end)
go bd.process(str, b, start, end)
return
}
func (bd *BruteDict) process(str []byte, b []byte, start int, end int) {
defer func() { recover() }()
for i := start; i <= end; i++ {
bd.list(str, b, i, 0)
}
bd.quit <- true
}
func (bd *BruteDict) Id() (str string) {
select {
case str = <-bd.queue:
case <-bd.quit:
}
return
}
func (bd *BruteDict) Close() {
bd.running = false
close(bd.queue)
}
func (bd *BruteDict) list(str []byte, b []byte, l int, j int) {
strl := len(str)
for i := 0; i < strl; i++ {
b[j] = str[i]
if j+1 < l {
bd.list(str, b, l, j+1)
} else {
bd.queue <- string(b)
}
}
}