-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcracker.go
67 lines (58 loc) · 1.36 KB
/
cracker.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
package zombie
import (
"bufio"
"encoding/hex"
"fmt"
"os"
"sync"
"github.com/btcsuite/btcutil/base58"
)
type Cracker func(string, *sync.WaitGroup)
func Dispatcher(fn Cracker, workers int, in <-chan string, wg *sync.WaitGroup) {
var i int
for i = 0; i < workers; i++ {
go func() {
for {
line, ok := <-in
if !ok {
break
}
fn(line, wg)
}
}()
}
wg.Wait()
}
func wifChecker(line string, wg *sync.WaitGroup) {
defer wg.Done()
result, _, err := base58.CheckDecode(line)
if err == nil {
fmt.Println("We found a valid Wif ", hex.EncodeToString(result))
fmt.Println("Wif ", line)
file, errFile := os.Create(hex.EncodeToString(result))
if errFile != nil {
panic(errFile.Error())
}
defer file.Close()
// Create a buffered writer from the file
bufferedWriter := bufio.NewWriter(file)
_, errorBuf := bufferedWriter.WriteString("line: " + line + "\nresult " + hex.EncodeToString(result) + "\n")
if errorBuf != nil {
panic(errorBuf.Error())
}
bufferedWriter.Flush()
}
}
func CrackWif(workers int, in <-chan string, wg *sync.WaitGroup) {
fmt.Println("Starting CrackWif")
Dispatcher(wifChecker, workers, in, wg)
wg.Wait()
fmt.Println("Done Crackwif")
}
func Print(in <-chan string, wg *sync.WaitGroup) {
Dispatcher(print, 1, in, wg)
}
func print(line string, wg *sync.WaitGroup) {
defer wg.Done()
fmt.Println(line)
}