-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (54 loc) · 1.17 KB
/
main.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
package main
import (
"bufio"
"encoding/hex"
"flag"
"fmt"
"log"
"os"
)
func main() {
var inputPath string
flag.StringVar(&inputPath, "InputFile", "none", "Specify the ascii hibp file")
var outputPath string
flag.StringVar(&outputPath, "OutputFile", "none", "Specify the name for the binary target file")
flag.Parse()
if inputPath == "none" || outputPath == "none" {
fmt.Println(os.Args[0])
flag.PrintDefaults()
os.Exit(1)
}
inputFile, err := os.Open(inputPath)
if err != nil {
log.Fatal(err)
}
defer inputFile.Close()
outputFile, err := os.Create(outputPath)
if err != nil {
log.Fatal(err)
}
defer outputFile.Close()
writer := bufio.NewWriter(outputFile)
scanner := bufio.NewScanner(inputFile)
for scanner.Scan() {
line := scanner.Text()
stringHash := line[:40]
data, err := hex.DecodeString(stringHash)
if err != nil {
log.Fatal(err)
}
bytesWritten, err := writer.Write(data)
if err != nil {
log.Fatal(err)
}
if bytesWritten != 20 {
log.Fatal("Write did not return 20 bytes. That is bad. Aborting!")
}
}
if err := writer.Flush(); err != nil {
log.Fatal(err)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}