|
| 1 | +Check-Digit Algorithms |
| 2 | +====================== |
| 3 | + |
| 4 | +``pii_text`` detects credit-card and IBAN *shapes* by regex and ``data_quality`` |
| 5 | +does type / range / regex validation, but nothing actually computes or verifies a |
| 6 | +*check digit*. This adds the shared arithmetic engine for the four schemes behind |
| 7 | +most real-world identifiers — and the primitive that account-number, card, IBAN, |
| 8 | +ISBN and EAN validation build on. |
| 9 | + |
| 10 | +Pure standard library (integer arithmetic; the Verhoeff and Damm tables are small |
| 11 | +embedded constants). Every function is pure (string in, bool / str out), so it is |
| 12 | +fully deterministic in CI. |
| 13 | + |
| 14 | +Headless API |
| 15 | +------------ |
| 16 | + |
| 17 | +.. code-block:: python |
| 18 | +
|
| 19 | + from je_auto_control import ( |
| 20 | + luhn_validate, luhn_check_digit, |
| 21 | + verhoeff_validate, verhoeff_check_digit, |
| 22 | + damm_validate, damm_check_digit, |
| 23 | + mod97_10_validate, mod97_10_check_digits, |
| 24 | + ) |
| 25 | +
|
| 26 | + luhn_validate("4111111111111111") # True (credit-card / IMEI) |
| 27 | + luhn_check_digit("7992739871") # '3' -> 79927398713 |
| 28 | + verhoeff_validate("2363") # True (catches transpositions) |
| 29 | + damm_check_digit("572") # '4' |
| 30 | + mod97_10_validate("3214282912345698765432161182") # True (IBAN engine) |
| 31 | +
|
| 32 | +- **Luhn** (mod 10): credit cards, IMEI, many national IDs — catches all |
| 33 | + single-digit errors and most adjacent transpositions. |
| 34 | +- **Verhoeff** and **Damm**: decimal schemes that catch *all* single-digit and |
| 35 | + adjacent-transposition errors (stronger than Luhn). |
| 36 | +- **ISO 7064 MOD 97-10**: the two-check-digit scheme behind IBAN and similar. |
| 37 | + |
| 38 | +Each scheme exposes ``*_validate(number)`` (does the value incl. its check digit |
| 39 | +verify?) and ``*_check_digit`` / ``*_check_digits`` (what digit(s) to append to a |
| 40 | +bare payload?). Non-digit characters are ignored, so spaced/grouped input works. |
| 41 | + |
| 42 | +Executor commands |
| 43 | +----------------- |
| 44 | + |
| 45 | +``AC_checksum_validate`` takes a ``scheme`` (``luhn`` / ``verhoeff`` / ``damm`` / |
| 46 | +``mod97``) plus a ``number`` and returns ``{valid}``; ``AC_checksum_digit`` returns |
| 47 | +``{check_digit}`` for a ``partial``. Both are exposed as MCP tools |
| 48 | +(``ac_checksum_validate`` / ``ac_checksum_digit``) and as Script Builder commands |
| 49 | +under **Data**. |
0 commit comments