Luhn algorithm – Credit card number verification
17 days ago
- #validation
- #check digit
- #Luhn algorithm
- The Luhn algorithm, also known as the 'modulus 10' algorithm, is a simple check digit formula used to validate identification numbers.
- Created by IBM scientist Hans Peter Luhn, it is in the public domain and widely used, specified in ISO/IEC 7812-1.
- It protects against accidental errors, not malicious attacks, and is used in credit card numbers and government IDs.
- The algorithm involves doubling every second digit from the right, summing the digits, and calculating a check digit.
- It detects most single-digit errors and transpositions but not all, like the sequence 09 to 90.
- More complex algorithms like Verhoeff and Damm can detect more errors, while Luhn mod N supports non-numerical strings.
- The algorithm is used in various systems globally, including credit cards, IMEI numbers, and national IDs.
- A pseudocode implementation checks the validity of a card number by verifying the check digit.