Repository navigation
Add Damm check digit algorithm - #15788
Open
NightSeclude wants to merge 1 commit into
Open
NightSeclude wants to merge 1 commit into
NightSeclude wants to merge 1 commit into
Conversation
Adds the Damm algorithm, which detects all single-digit errors and all adjacent transposition errors. The 10x10 quasigroup table is documented and validated by doctests that cover valid numbers, wrong check digits, and invalid input types. Co-Authored-By: Claude Code <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change
Checklist
What this adds
hashes/damm.pyimplements the Damm algorithm, a check digit algorithm based on a weakly totally anti-symmetric quasigroup of order 10. It detects all single-digit errors and all adjacent transposition errors, which is the property Luhn lacks for transpositions of09/90.Functions:
damm_checksum(number: str) -> int— interim digit after processing every digit; a complete number is valid iff this is0.generate_check_digit(number: str) -> str— the digit to append to a payload.is_valid(number: str) -> bool— validity of a number that already carries its check digit.Verification
python hashes/damm.py(doctests): passes.ruff check hashes/damm.pyandruff format --check hashes/damm.py: clean.0-9, the main diagonal is all zeros, and the table is totally anti-symmetric ((x*a)*b == (x*b)*aonly whena == b).