Start work on l33t.

This commit is contained in:
Nathan Button 2016-01-27 17:11:50 -07:00
parent 9f59e087f7
commit 58d1351487
4 changed files with 88 additions and 21 deletions

View File

@ -21,6 +21,7 @@ func init() {
AdjacencyGph["dvorak"] = BuildDvorak() AdjacencyGph["dvorak"] = BuildDvorak()
AdjacencyGph["keypad"] = BuildKeypad() AdjacencyGph["keypad"] = BuildKeypad()
AdjacencyGph["macKeypad"] = BuildMacKeypad() AdjacencyGph["macKeypad"] = BuildMacKeypad()
AdjacencyGph["l33t"] = BuildLeet()
} }
func BuildQwerty() AdjacencyGraph { func BuildQwerty() AdjacencyGraph {
@ -51,6 +52,13 @@ func BuildMacKeypad() AdjacencyGraph {
} }
return GetAdjancencyGraphFromFile(data, "mac_keypad") return GetAdjancencyGraphFromFile(data, "mac_keypad")
} }
func BuildLeet() AdjacencyGraph {
data, err := zxcvbn_data.Asset("data/L33t.json")
if err != nil {
panic("Can't find asset")
}
return GetAdjancencyGraphFromFile(data, "keypad")
}
func GetAdjancencyGraphFromFile(data []byte, name string) AdjacencyGraph { func GetAdjancencyGraphFromFile(data []byte, name string) AdjacencyGraph {

View File

@ -8,7 +8,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
// "github.com/deckarep/golang-set" // "github.com/deckarep/golang-set"
"github.com/nbutton23/zxcvbn-go/entropy" "github.com/nbutton23/zxcvbn-go/entropy"
) )
@ -65,6 +65,7 @@ func loadFrequencyList() {
KEYBOARD_STARTING_POSITIONS = len(adjacency.AdjacencyGph["querty"].Graph) KEYBOARD_STARTING_POSITIONS = len(adjacency.AdjacencyGph["querty"].Graph)
KEYPAD_AVG_DEGREE = adjacency.AdjacencyGph["keypad"].CalculateAvgDegree() KEYPAD_AVG_DEGREE = adjacency.AdjacencyGph["keypad"].CalculateAvgDegree()
KEYPAD_STARTING_POSITIONS = len(adjacency.AdjacencyGph["keypad"].Graph) KEYPAD_STARTING_POSITIONS = len(adjacency.AdjacencyGph["keypad"].Graph)
L33T_TABLE = adjacency.AdjacencyGph["l33t"]
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["qwerty"]) ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["qwerty"])
ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["dvorak"]) ADJACENCY_GRAPHS = append(ADJACENCY_GRAPHS, adjacency.AdjacencyGph["dvorak"])
@ -319,35 +320,84 @@ func spatialMatchHelper(password string, graph adjacency.AdjacencyGraph) (matche
return matches return matches
} }
func relevantL33tSubtable(password string) adjacency.AdjacencyGraph {
var releventSubs adjacency.AdjacencyGraph
for _, char := range password {
if len(L33T_TABLE.Graph[string(char)]) > 0 {
releventSubs.Graph[string(char)] = L33T_TABLE.Graph[string(char)]
}
}
return releventSubs func l33tMatch(password string) []match.Match {
return nil
} }
//TODO yeah this is a little harder than i expect. . . //TODO: what is the return value of this?
//func enumerateL33tSubs(table adjacency.AdjacencyGraph) []string { //func enumerateL33tSubs(table map[string]string) []string {
//
// //subs = [[]]
// var subs [][]string // 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
// //
// dedup := func(subs []string) []string { // for _, sub := range subsSlice {
// deduped := mapset.NewSetFromSlice(subs)
// return deduped.ToSlice()
// }
//
// for i,v := range table.Graph {
// var nextSubs []string
// for _, subChar := range v {
// //
// } // }
//
// } // }
// /*
// 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)
for key, values := range L33T_TABLE.Graph {
for _, value := range values {
if strings.Contains(password, value) {
relevantSubs[value] = key
}
}
}
return relevantSubs
}
func RepeatMatch(password string) []match.Match { func RepeatMatch(password string) []match.Match {
var matches []match.Match var matches []match.Match

View File

@ -120,3 +120,12 @@ func TestDateWithoutSepMatch(t *testing.T) {
matches := dateWithoutSepMatch("11091991") matches := dateWithoutSepMatch("11091991")
assert.Len(t, matches, 1, "Lenght should be 1") assert.Len(t, matches, 1, "Lenght should be 1")
} }
//l33t
func TestLeetSubTable(t *testing.T){
subs := relevantL33tSubtable("password")
assert.Len(t, subs, 0, "password should produce no leet subs")
subs = relevantL33tSubtable("p4ssw0rd")
assert.Len(t, subs, 2, "p4ssw0rd should produce 2 subs")
}