Skip to content

fix(ess-passwords): count entropy without replacement - #141

Merged
mattnorris merged 1 commit into
mainfrom
passwords
Oct 6, 2026
Merged

mattnorris merged 1 commit into
mainfrom
passwords

Conversation

@mattnorris

Copy link
Copy Markdown
Collaborator

Summary

  • Count entropy as an ordered draw without replacement, the sum of log2(N - i) per word, instead of word_count * log2(N).
  • Raise PasswordPolicyError when word_count exceeds the filtered wordlist, instead of letting xkcdpass raise ValueError.
  • Add PasswordLengthError, a PasswordPolicyError subclass, for a max_length too small for the word count. It is exported from the package.
  • Document that entropy_bits is an upper bound when max_length is set, and that --json carries entropy in the payload and skips the stderr note.

Test plan

  • uv run pytest packages/python/ess-passwords (37 passed), including new tests for entropy without replacement, the word-count limit, and the --json stderr behaviour.

Words are drawn without replacement, so entropy is now the sum of
log2(N - i) per draw. A word count above the filtered wordlist raises
PasswordPolicyError, and a max_length too small for the word count raises
the new PasswordLengthError. Document that entropy is an upper bound under
max_length and that --json omits the stderr note.
@mattnorris
mattnorris merged commit 3d63acb into main Oct 6, 2026
1 check passed
@mattnorris
mattnorris deleted the passwords branch October 6, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant