Damm Algorithm — Definition, Formula & Example
The Damm algorithm is a check-digit method that runs the digits of a number through a 10-by-10 lookup table and appends one extra digit. If anyone mistypes a single digit or swaps two neighboring digits, the number fails the check.
Let be a quasigroup operation on , so its table is a Latin square. It must be weakly totally anti-symmetric: for all , implies . It must also satisfy . For digits , the check digit is . A string is accepted exactly when running it through the table from 0 ends at 0. Appending always passes because .
Key Formula
Where:
- = The fixed 10-by-10 table; the first input picks the row and the second picks the column
- = The i-th digit of the number, read from left to right
- = The interim digit after the first i digits are processed, starting from 0
- = The check digit, equal to the final interim digit
Worked Example
Problem: Use the standard Damm table to find the check digit for 312. Then show that the typo 1328, with the first two digits swapped, is rejected. You need these entries: row 0 is 0 3 1 7 5 9 8 6 4 2, row 1 is 7 0 9 2 1 5 4 8 6 3, row 3 is 1 7 5 0 9 8 3 4 2 6, row 7 is 8 9 4 5 3 6 2 0 1 7, row 8 is 9 4 3 8 6 1 7 2 0 5, and row 9 is 2 5 8 1 4 3 6 7 9 0. Columns are numbered 0 to 9.
Step 1: Start with interim digit 0. For digit 3, read row 0, column 3, which gives 7. For digit 1, read row 7, column 1, which gives 9.
Step 2: For digit 2, read row 9, column 2, which gives 8. That final interim digit is the check digit, so the full number is 3128. To verify it, run one more lookup with the check digit: row 8, column 8 is 0, so 3128 passes.
Step 3: Run the typo 1328 from 0. Row 0, column 1 gives 3. Row 3, column 3 gives 0. Row 0, column 2 gives 1. Row 1, column 8 gives 6. The result is not 0, so the swap is caught.
Answer: The check digit is 8, so you transmit 3128. The transposed string 1328 ends at 6 instead of 0, so the algorithm rejects it.
Why It Matters
H. Michael Damm introduced the method in 2004. It catches every single-digit error and every adjacent swap, which matches the Verhoeff algorithm. Verhoeff needs three tables (a dihedral multiplication table, a permutation table, and an inverse table), while Damm needs one. The Luhn algorithm on credit cards is simpler, but it misses the swap 09 to 90.
Common Mistakes
Mistake: Reading the table with the new digit as the row and the interim digit as the column.
Correction: The operation is not commutative. In the example, row 0, column 3 gives 7, but row 3, column 0 gives 1. Always use the current interim digit for the row and the next digit of the number for the column.
