2026-02-26
The syntax of credit card numbers
Publication
Publication
The numbers on credit cards (and other similar identification numbers) consist of a string of digits. These are traditionally checked for semi-validity using the Luhn algorithm, defined in Annex B of ISO/IEC 7812-1, which is a right-to-left mathematical check-sum style algorithm that guards against common errors such as mistyping single digits, and interchanging adjacent digits. This paper considers how although the Luhn algorithm is a mathematical function, surprisingly its effect can be expressed using a grammar, and that therefore credit card numbers actually have an internal, albeit complex, syntax. The paper explains the method behind how this works, and then in a number of steps, develops firstly a grammar that requires a general parser such as ixml's to verify credit card numbers, and then uses that to generate an LL1 grammar working left-to-right that achieves the same purpose. The resultant grammar is large, of the order of a hundred rules, but is so systematic that it can be generated mechanically by a program.
| Additional Metadata | |
|---|---|
| The First International Symposium on Invisible XML | |
| Organisation | Distributed and Interactive Systems |
|
Pemberton, S. (2026, February 26). The syntax of credit card numbers. Presentations of the First International Symposium on Invisible XML, 2026. |
|