Skip to content

Instantly share code, notes, and snippets.

@nbutton23
Created May 29, 2016 21:28
Show Gist options
  • Save nbutton23/b11f57561c6471890bd95ac5a3b52a75 to your computer and use it in GitHub Desktop.
Save nbutton23/b11f57561c6471890bd95ac5a3b52a75 to your computer and use it in GitHub Desktop.
func dictionaryMatch(password string, dictionaryName string, rankedDict map[string]int) []match.Match {
length := len(password)
var results []match.Match
pwLower := strings.ToLower(password)
for i := 0; i < length; i++ {
for j := i; j < length; j++ {
word := pwLower[i : j+1]
if val, ok := rankedDict[word]; ok {
matchDic := match.Match{Pattern: "dictionary",
DictionaryName: dictionaryName,
I: i,
J: j,
Token: password[i : j+1],
}
matchDic.Entropy = entropy.DictionaryEntropy(matchDic, float64(val))
results = append(results, matchDic)
}
}
}
return results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment