-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
109 lines (93 loc) · 2.28 KB
/
main.go
File metadata and controls
109 lines (93 loc) · 2.28 KB
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 main
import (
"bufio"
"fmt"
flag "github.com/spf13/pflag"
"os"
"strings"
)
var (
minElems *int
maxElems *int
wordlist *string
outputFile *string
)
type outFile struct {
fp *os.File
buf *bufio.Writer
}
// Reads the wordlist into a slice of words
func processWordlist(inputFile string) ([]string, error) {
var scanner *bufio.Scanner
var words []string
if inputFile == "" {
scanner = bufio.NewScanner(os.Stdin)
} else {
file, err := os.Open(inputFile)
if err != nil {
return nil, err
}
defer file.Close()
scanner = bufio.NewScanner(file)
}
// reading words from input
fmt.Println("No wordlist detected.\nYou can now manually enter words; Please submit your first word:")
var lineBreaks int
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if line != "" {
words = append(words, line)
} else {
lineBreaks++
if lineBreaks >= 2 {
break
}
fmt.Println("Press [ENTER] one more time to submit your wordlist.")
}
}
return words, scanner.Err()
}
func init() {
minElems = flag.IntP("min", "n", 2, "Minimum number of elements per chain")
maxElems = flag.IntP("max", "m", 4, "Maximum number of elements per chain")
wordlist = flag.StringP("wordlist", "i", "", "Path to input wordlist file (default STDIN)")
outputFile = flag.StringP("output", "o", "", "Path to output file (default STDOUT)")
wordSeparator := flag.StringP("separator", "s", string(Separator), "Separator used between elements")
flag.Parse()
if len(os.Args) > 1 && os.Args[1] == `help` {
flag.Usage()
os.Exit(0)
}
// Validate element count range
if *minElems < 1 || *maxElems < *minElems {
fmt.Printf("Error: --min must be ≥ 1 and ≤ --max\n")
os.Exit(1)
}
// Read words from the wordlist
var err error
Dictionary, err = processWordlist(*wordlist)
if err != nil {
fmt.Printf("Failed to process wordlist: %v\n", err)
os.Exit(1)
}
Separator = []byte(*wordSeparator)[0]
}
func main() {
var (
fp *os.File
err error
)
if *outputFile != "" {
fp, err = os.Create(*outputFile)
if err != nil {
fmt.Printf("Error opening output file: %v\n", err)
os.Exit(1)
}
} else {
fp = os.Stdout
}
defer fp.Close()
output := &outFile{fp, bufio.NewWriterSize(fp, 16*1024*1024)}
generateChains(*minElems, *maxElems, output)
output.buf.Flush()
}