Produce selected algorithm implementations.
Initialising algorithm engine for Check Digit Code Generator...
How Check Digit Code Generator Works?
The Check Digit Code Generator works by filling a language template with the selected algorithm's weights, modulus, and mapping, then returning a ready-to-use function with a test call.
- 1Select the algorithm.
- 2Select the language: JavaScript, Python, PHP, Java, C#, or SQL.
- 3Generate the function with input clean-up and the check calculation.
- 4Add a test call with a published reference vector.
- 5Copy the code into the project.
Check Digit Code Generator Formula
The generator output is function(payload) → check character, built from the same parameters as the calculators on this site.
template(language, { weights, modulus, direction, mapping }) → source code
assert f(reference_payload) == reference_checkreference_payloadis a published test value.
def luhn(p): s = sum((2*d - 9 if 2*d > 9 else 2*d) if i % 2 == 0 else d for i, d in enumerate(map(int, reversed(p))))
return (10 - s % 10) % 10
luhn('7992739871') → 3Check Digit Code Generator Conversion Table
The code generator table lists tested Python and JavaScript functions for 6 algorithms; each one was run against the test input shown.
| Algorithm | Python | JavaScript | Test input | Output |
|---|---|---|---|---|
| Luhn | def luhn(p): s = sum((2*d - 9 if 2*d > 9 else 2*d) if i % 2 == 0 else d for i, d in enumerate(map(int, reversed(p)))); return (10 - s % 10) % 10 | const luhn = p => { let s = 0; [...p].reverse().forEach((c, i) => { let d = +c; if (i % 2 === 0) { d *= 2; if (d > 9) d -= 9; } s += d; }); return (10 - s % 10) % 10; }; | 7992739871 | 3 |
| GS1 Mod 10 | def gs1(p): s = sum(int(d) * (3 if i % 2 == 0 else 1) for i, d in enumerate(reversed(p))); return (10 - s % 10) % 10 | const gs1 = p => { const s = [...p].reverse().reduce((a, c, i) => a + (+c) * (i % 2 ? 1 : 3), 0); return (10 - s % 10) % 10; }; | 590123412345 | 7 |
| ISBN-10 | def isbn10(p): c = (11 - sum(int(d) * (10 - i) for i, d in enumerate(p)) % 11) % 11; return 'X' if c == 10 else str(c) | const isbn10 = p => { const c = (11 - [...p].reduce((a, d, i) => a + (+d) * (10 - i), 0) % 11) % 11; return c === 10 ? 'X' : String(c); }; | 080442957 | X |
| IBAN | def iban(cc, bban): n = int(''.join(str(int(ch, 36)) for ch in bban + cc + '00')); return f'{98 - n % 97:02d}' | const iban = (cc, b) => { const n = BigInt([...(b + cc + '00')].map(ch => parseInt(ch, 36)).join('')); return String(98n - n % 97n).padStart(2, '0'); }; | GB / WEST12345698765432 | 82 |
| Spanish NIF | def nif(n): return 'TRWAGMYFPDXBNJZSQVHLCKE'[int(n) % 23] | const nif = n => 'TRWAGMYFPDXBNJZSQVHLCKE'[Number(n) % 23]; | 12345678 | Z |
| ISO 7064 MOD 11-2 | def mod11_2(p): ⏎ t = 0 ⏎ for d in p: t = (t + int(d)) * 2 % 11 ⏎ c = (12 - t) % 11 ⏎ return 'X' if c == 10 else str(c) | const mod11_2 = p => { let t = 0; for (const d of p) t = (t + +d) * 2 % 11; const c = (12 - t) % 11; return c === 10 ? 'X' : String(c); }; | 000000021825009 | 7 |
What is Check Digit Code Generator?
A Check Digit Code Generator is a tool that writes check digit functions in common programming languages. The output saves developers from re-deriving weights and mapping rules.
Every generated function ships with a reference test, so the code can be checked before it reaches production.
What are the uses of Check Digit Code Generator?
There are 3 main uses of the Check Digit Code Generator, including form validation, backend services, and database checks.
- Form validation: Front-end developers add checks to input fields.
- Backend services: API developers validate identifiers on the server.
- Database checks: DBAs add constraints in SQL.