diff --git a/dict/dict.go b/dict/dict.go new file mode 100644 index 0000000..46f0087 --- /dev/null +++ b/dict/dict.go @@ -0,0 +1,77 @@ +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( + "", +).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() +} diff --git a/go.mod b/go.mod index 66195d8..7dbaeed 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module surdeus.su/util/combo go 1.16 -require surdeus.su/core/cli v0.6.0 +require surdeus.su/core/cli v0.8.0 diff --git a/go.sum b/go.sum index 5a24746..78a56d9 100644 --- a/go.sum +++ b/go.sum @@ -2,3 +2,7 @@ golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= surdeus.su/core/cli v0.6.0 h1:ezyBljhVn+lTcIMPblUMsQzaXQ+xzkzZ9ZYLcirZwEI= surdeus.su/core/cli v0.6.0/go.mod h1:r9JtQz3aEJzpYzMaNUNQHJoYkoWKNPi047qhd5uGlmA= +surdeus.su/core/cli v0.7.0 h1:4IBN6PyZp6BUTC2mrDPudCjUbs/fs6Pv1KG/Ua/vBCI= +surdeus.su/core/cli v0.7.0/go.mod h1:r9JtQz3aEJzpYzMaNUNQHJoYkoWKNPi047qhd5uGlmA= +surdeus.su/core/cli v0.8.0 h1:HGmRqWl6W5DxFX1nVkUpS+cK0BgYYJdYrZY3VTq3C4k= +surdeus.su/core/cli v0.8.0/go.mod h1:r9JtQz3aEJzpYzMaNUNQHJoYkoWKNPi047qhd5uGlmA= diff --git a/main.go b/main.go index 7e39020..7588b17 100644 --- a/main.go +++ b/main.go @@ -2,14 +2,17 @@ package main import ( "os" - "surdeus.su/util/combo/tmpl" - "surdeus.su/util/combo/pin" + "surdeus.su/core/cli/mtool" + "surdeus.su/util/combo/dict" + "surdeus.su/util/combo/pin" + "surdeus.su/util/combo/tmpl" ) var root = mtool.T("combo").Subs( tmpl.Tool, pin.Tool, + dict.Tool, ) func main() { diff --git a/pin/pin.go b/pin/pin.go index 0479faa..9a23e43 100644 --- a/pin/pin.go +++ b/pin/pin.go @@ -12,7 +12,7 @@ import ( var ( delim rune = '\n' - Tool = mtool.T("pin").Func(Run).Desc( + Tool = mtool.T("pin").Func(Run).Desc( "print all the possible PIN combinations made of custom characters", ).Usage( "", @@ -21,7 +21,7 @@ var ( func Pow(x, p int) int { ret := 1 - for i:=0 ; i