Skip to content

Commit

Permalink
Fix NoList entropy bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GGP1 committed Jan 9, 2021
1 parent d02653c commit a778f24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 6 additions & 5 deletions passphrase.go
Expand Up @@ -187,15 +187,16 @@ func (p *Passphrase) Entropy() float64 {
if len(p.words) == 0 {
return 0
}

words := strings.Join(p.words, "")
// Take out the separators from the secret length
// Included and excluded words aren't taken into account
secretLength := len(p.words) - (len(p.Separator) * int(p.Length))
// -26- represents the dictionary length
secretLength := len(words) - (len(p.Separator) * int(p.Length))
// -26- represents the dictionary length (vowels+constants)
return math.Log2(math.Pow(float64(26), float64(secretLength)))
case "WordList":
poolLength = 18325
poolLength = len(atollWords)
case "SyllableList":
poolLength = 10129
poolLength = len(atollSyllables)
}

poolLength += len(p.Include) - len(p.Exclude)
Expand Down
3 changes: 1 addition & 2 deletions passphrase_test.go
Expand Up @@ -175,7 +175,7 @@ func TestPassphraseEntropy(t *testing.T) {

// NoList entropy changes everytime as it generates random words
if getFuncName(tc.list) == "NoList" {
secretLength := len(p.words) - (len(p.Separator) * int(p.Length))
secretLength := len(strings.Join(p.words, "")) - (len(p.Separator) * int(p.Length))
tc.expected = math.Log2(math.Pow(float64(26), float64(secretLength)))
}

Expand All @@ -196,7 +196,6 @@ func TestPassphraseEntropyNoSecret(t *testing.T) {

var expected float64 = 0
got := p.Entropy()

if got != expected {
t.Errorf("Expected %f, got %f", expected, got)
}
Expand Down

0 comments on commit a778f24

Please sign in to comment.