passwords now passing through the 1337 matcher. Not sure if scoring is correct.
This commit is contained in:
parent
7725100293
commit
54e42d230c
|
@ -156,7 +156,7 @@ func SequenceEntropy(match match.Match, dictionaryLength int, ascending bool) fl
|
|||
baseEntropy = float64(0)
|
||||
} else {
|
||||
baseEntropy = math.Log2(float64(dictionaryLength))
|
||||
//TODO: should this be just the first or any char
|
||||
//TODO: should this be just the first or any char?
|
||||
if unicode.IsUpper(rune(firstChar)) {
|
||||
baseEntropy++
|
||||
}
|
||||
|
@ -167,3 +167,28 @@ func SequenceEntropy(match match.Match, dictionaryLength int, ascending bool) fl
|
|||
}
|
||||
return baseEntropy + math.Log2(float64(len(match.Token)))
|
||||
}
|
||||
|
||||
func ExtraLeetEntropy(match match.Match, password string) float64 {
|
||||
var subsitutions float64
|
||||
var unsub float64
|
||||
subPassword := password[match.I:match.J]
|
||||
for index, char := range subPassword {
|
||||
if string(char) != string(match.Token[index]) {
|
||||
subsitutions++
|
||||
} else {
|
||||
//TODO: Make this only true for 1337 chars that are not subs?
|
||||
unsub++
|
||||
}
|
||||
}
|
||||
|
||||
var possibilities float64
|
||||
|
||||
for i := float64(0); i <= math.Min(subsitutions, unsub)+1; i++ {
|
||||
possibilities += zxcvbn_math.NChoseK(subsitutions+unsub, i)
|
||||
}
|
||||
|
||||
if possibilities <= 1 {
|
||||
return float64(1)
|
||||
}
|
||||
return math.Log2(possibilities)
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ func loadFrequencyList() {
|
|||
MATCHERS = append(MATCHERS, SpatialMatch)
|
||||
MATCHERS = append(MATCHERS, RepeatMatch)
|
||||
MATCHERS = append(MATCHERS, SequenceMatch)
|
||||
MATCHERS = append(MATCHERS, l33tMatch)
|
||||
|
||||
}
|
||||
|
||||
|
@ -322,9 +323,25 @@ func spatialMatchHelper(password string, graph adjacency.AdjacencyGraph) (matche
|
|||
|
||||
func l33tMatch(password string) []match.Match {
|
||||
|
||||
subsitutions := relevantL33tSubtable(password)
|
||||
|
||||
permutations := getAllPermutationsOfLeetSubstitutions(password, subsitutions)
|
||||
|
||||
return nil
|
||||
var matches []match.Match
|
||||
|
||||
for _, permutation := range permutations {
|
||||
for _, mather := range DICTIONARY_MATCHERS {
|
||||
matches = append(matches,mather(permutation)...)
|
||||
}
|
||||
}
|
||||
|
||||
for _, match := range matches {
|
||||
println(match.Entropy)
|
||||
match.Entropy += entropy.ExtraLeetEntropy(match, password)
|
||||
println(match.Entropy)
|
||||
}
|
||||
|
||||
return matches
|
||||
}
|
||||
|
||||
func getAllPermutationsOfLeetSubstitutions(password string, substitutionsMap map[string][]string) []string {
|
||||
|
@ -353,63 +370,6 @@ func getAllPermutationsOfLeetSubstitutions(password string, substitutionsMap map
|
|||
|
||||
return permutations
|
||||
}
|
||||
//TODO: what is the return value of this?
|
||||
//func enumerateL33tSubs(table map[string]string) []string {
|
||||
//
|
||||
// //subs = [[]]
|
||||
// var subs [][]string
|
||||
// /*
|
||||
// def dedup(subs):
|
||||
// deduped = []
|
||||
// members = set()
|
||||
// for sub in subs:
|
||||
// key = str(sorted(sub))
|
||||
// if key not in members:
|
||||
// deduped.append(sub)
|
||||
// return deduped
|
||||
// */
|
||||
// dedup := func(subsSlice []string){
|
||||
// var deduped []string
|
||||
//
|
||||
// for _, sub := range subsSlice {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// /*
|
||||
// keys = table.keys()
|
||||
// while len(keys) > 0:
|
||||
// first_key = keys[0]
|
||||
// rest_keys = keys[1:]
|
||||
// next_subs = []
|
||||
// for l33t_chr in table[first_key]:
|
||||
// for sub in subs:
|
||||
// dup_l33t_index = -1
|
||||
// for i in range(0, len(sub)):
|
||||
// if sub[i][0] == l33t_chr:
|
||||
// dup_l33t_index = i
|
||||
// break
|
||||
// if dup_l33t_index == -1:
|
||||
// sub_extension = list(sub)
|
||||
// sub_extension.append((l33t_chr, first_key))
|
||||
// next_subs.append(sub_extension)
|
||||
// else:
|
||||
// sub_alternative = list(sub)
|
||||
// sub_alternative.pop(dup_l33t_index)
|
||||
// sub_alternative.append((l33t_chr, first_key))
|
||||
// next_subs.append(sub)
|
||||
// next_subs.append(sub_alternative)
|
||||
// subs = dedup(next_subs)
|
||||
// keys = rest_keys
|
||||
// return map(dict, subs)
|
||||
//
|
||||
// */
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// //TODO: Remove
|
||||
// return nil
|
||||
//}
|
||||
|
||||
func relevantL33tSubtable(password string) map[string][]string {
|
||||
relevantSubs := make(map[string][]string)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/nbutton23/zxcvbn-go/match"
|
||||
"strings"
|
||||
"testing"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
//DateSepMatch("1991-09-11jibjab11.9.1991")
|
||||
|
@ -167,4 +168,11 @@ func TestPermutationsOfLeetSubstitutions(t *testing.T){
|
|||
possibleSubs = relevantL33tSubtable(password)
|
||||
permutations = getAllPermutationsOfLeetSubstitutions(password, possibleSubs)
|
||||
assert.Len(t, permutations, 35, "check my math 3*2*2*3 -1 ")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeet(t *testing.T){
|
||||
password := "p4ssw0rd"
|
||||
matches := l33tMatch(password)
|
||||
|
||||
fmt.Println(matches[0].J)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ Use these test to see how close to feature parity the library is.
|
|||
*/
|
||||
|
||||
const (
|
||||
allowableError = float64(0.01)
|
||||
allowableError = float64(0.05)
|
||||
)
|
||||
|
||||
type failedTest struct {
|
||||
|
|
Loading…
Reference in New Issue