77 lines
1.1 KiB
Go
77 lines
1.1 KiB
Go
package dict
|
|
|
|
import (
|
|
"os"
|
|
|
|
"io"
|
|
"sync"
|
|
|
|
"strconv"
|
|
|
|
"surdeus.su/core/cli/mtool"
|
|
"surdeus.su/util/combo/pin"
|
|
"surdeus.su/util/combo/tmpl"
|
|
)
|
|
|
|
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
var Tool = mtool.T("dict").Func(Run).Usage(
|
|
"<token1 token2 ... [token3]>",
|
|
).Desc("make password dictionary from custom tokens")
|
|
|
|
func Run(
|
|
flags *mtool.Flags,
|
|
) {
|
|
var (
|
|
maxLen int
|
|
)
|
|
|
|
flags.IntVar(
|
|
&maxLen,
|
|
"max", 2, "max tokens in output passwords",
|
|
)
|
|
tokens := flags.Parse()
|
|
if len(tokens) < 2 {
|
|
flags.Usage()
|
|
os.Exit(1)
|
|
}
|
|
if len(tokens) > len(alphabet) {
|
|
flags.Usage()
|
|
os.Exit(1)
|
|
}
|
|
|
|
c := alphabet[:len(tokens)]
|
|
|
|
var (
|
|
wg sync.WaitGroup
|
|
)
|
|
|
|
input, output := io.Pipe()
|
|
|
|
wg.Add(1)
|
|
go func() {
|
|
pin.Tool.Run([]string{
|
|
"-c", c,
|
|
"-m", "-max-reps", "1",
|
|
"-max-len", strconv.Itoa(maxLen),
|
|
"--",
|
|
},
|
|
io.Reader(os.Stdin), io.Writer(output),
|
|
)
|
|
output.Close()
|
|
wg.Done()
|
|
}()
|
|
|
|
wg.Add(1)
|
|
go func() {
|
|
tmpl.Tool.Run(append([]string{
|
|
"-c", c,
|
|
"--",
|
|
}, tokens...),
|
|
io.Reader(input), io.Writer(os.Stdout),
|
|
)
|
|
input.Close()
|
|
wg.Done()
|
|
}()
|
|
|
|
wg.Wait()
|
|
}
|