From a778f2490067d4e920b7c5b3f9e29a58a409371f Mon Sep 17 00:00:00 2001 From: GGP1 Date: Sat, 9 Jan 2021 16:53:13 -0300 Subject: [PATCH] Fix NoList entropy bug --- passphrase.go | 11 ++++++----- passphrase_test.go | 3 +-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/passphrase.go b/passphrase.go index b93728f..e2a3e8b 100644 --- a/passphrase.go +++ b/passphrase.go @@ -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) diff --git a/passphrase_test.go b/passphrase_test.go index 680d54a..3cb9b52 100644 --- a/passphrase_test.go +++ b/passphrase_test.go @@ -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))) } @@ -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) }