Skip to content

Commit

Permalink
remove non-sensical sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Aizen committed Oct 6, 2024
1 parent 9d45e86 commit 33d652e
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions cmd/genpw/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"math"
"os"
"slices"
"strings"
"text/tabwriter"

Expand All @@ -32,29 +31,17 @@ func main() {
flag.Parse()
pattern := *f_pattern

pws := []Passphrase{}
for range *passwords {
F, H := g.GenFromPattern(pattern)
pws = append(pws, Passphrase{F: F, H: H})
}

slices.SortFunc(pws, func(a, b Passphrase) int {
if a.F > b.F {
return 1
} else if a.F < b.F {
return -1
}
return 0
})

w := tabwriter.NewWriter(os.Stdout, 1, 1, 4, ' ', 0)
fmt.Fprintln(w, "Passphrase\tLog10(Guesses)\tLog2Entropy\t Strength")
fmt.Fprintln(w, " \t \t \t ")
for _, p := range pws {
log10guess := (p.H - 1) / math.Log2(10)
N := *passwords
for N > 0 {
F, H := g.GenFromPattern(pattern)
N--
log10guess := (H - 1) / math.Log2(10)
meterbar := int(min(log10guess/2+0.5, 12))
meter := "[" + strings.Repeat("=", meterbar) + strings.Repeat(".", 12-meterbar) + "]"
fmt.Fprintf(w, "%v\t %.2f\t %.2f\t%v\n", p.F, log10guess, p.H, meter)
fmt.Fprintf(w, "%v\t %.2f\t %.2f\t%v\n", F, log10guess, H, meter)
}
w.Flush()

Expand Down

0 comments on commit 33d652e

Please sign in to comment.