Check Digit Tool
Download a Python tool that tests the check digit of a card number, ISBN, EAN-13 or IBAN, and see which typos each scheme catches.
One file, Python standard library only, no install. Tested here on Python 3.11 only. Run python3 checkdigits.py check VALUE; it exits 0 if every value passes, 1 if any fails. Made by Claude, an AI model. README
Using it
Spaces, hyphens and dots are ignored. With no -s option the tool guesses from the shape: two letters and two digits is an IBAN, ten characters is an ISBN-10, thirteen digits is an ISBN-13 (if it starts 978 or 979) or an EAN-13, any other run of digits is Luhn. A ten-digit card or ID number therefore needs -s luhn.
Both blocks are pasted from real runs of the script in this folder (Python 3.11). A pass means the digits fit the arithmetic. It does not mean the card, book, product or account exists.
Try the same rules here
This box runs checkdigits.js, a line-for-line port of the Python rules, because a web page cannot run the script. The audit below uses the same port.
What each scheme checks
- Luhn Double every second digit from the right, fold two-digit results back to one digit, add everything up; the total must end in 0.
- ISBN-10 Weight the digits 10, 9, ... 1 (a final X counts as 10); the total must divide by 11.
- EAN-13 Weight the digits 1, 3, 1, 3, ... from the left; the total must divide by 10. An ISBN-13 is the same sum on a number that starts 978 or 979.
- IBAN Move the first four characters to the end, turn letters into 10 to 35, read the result as one big number; its remainder after dividing by 97 must be 1.
Which typos does each one catch?
A check digit is a bet: most mistakes change the sum, a few do not. The page below tests it by trying. For each scheme it builds valid codes from a seeded random generator, then on every code it makes every single-symbol substitution (one position replaced by any other symbol allowed there) and every adjacent swap of two different symbols, and asks the checker whether it notices. Every count below is produced by that loop when the page loads.
Starting...
Checked against published examples
Loading the examples...
| Group | Scheme | Examples | Agree | Disagree |
|---|