Dernière modificationdéc. 20202 min lues
Algorithms have a tremendous impact on our society, and the Luhn Algorithm proves exactly this. The Luhn Algorithm helps to determine the accuracy of identification numbers in major credit cards and number sequences, flagging any error in the numbers provided.
Luhn Algorithm Explained
Luhn Algorithm, or Modulus 10 Algorithm, is a mathematical formula that helps to determine whether or not a correct identification number has been provided. It is named after its creator, German Computer Scientist Hans Peter Luhn, who developed the Luhn Algorithm formula in 1954 during his days as an IBM researcher. However, the modular arithmetic on which the Luhn algorithm runs was developed by Carl Friedrich Guass in the 19th Century.
The Luhn algorithm helps to validate identification numbers, which explains why it’s widely used in electronic payment systems, most notably credit cards and number sequences like Social Security Numbers. Due to its ability to rapidly identify wrong card numbers, the algorithm typically speeds up electronic payment processing,
However, payment systems must first integrate the Luhn Algorithm into their programs, so they’re able to detect any errors in the information inputted into them. What’s more, such errors will be raised timeously, without having to wait for the transaction details to report the transaction unapproved.
How does the Luhn Algorithm work?
This will be explained with a Visa number: 4003600000000014
1. Multiply the digits from the back, starting from the second-to-last. Skip one number, double the next until you’re now on the first number.
1 x 2 + 0 x 2 + 0 x 2 + 0 x 2 + 0 x 2 + 6 x 2 + 0 x 2 + 4 x 2
2. Now, we have product digits for all doubled digits, e.g. the product digit of 1 × 2 is 2. However, the product digit of 6 × 2 will be 1 + 2 (derived from its product '12') because 12 is higher than 10. Add all the derived product digits together.
= 2 + 0 + 0 + 0 + 0 + 1 + 2 + 0 + 8 = 13
3. The sum derived should be added to the sum of the digits that weren’t doubled.
13 + 4 + 0 + 0 + 0 + 0 + 0 + 3 + 0 = 20
4. If the last digit in the total is 0, then the set of numbers is valid.
The last digit in 20 is 0. So, the Visa number is correct.
Real life application of the Luhn Algorithm
An error report usually comes up where wrong account information is inputted into an electronic payment system. This is because the resulting number generated by the algorithm after a set of numbers is entered doesn’t match the expected resulting number assigned by the Luhn Algorithm to that set of numbers. That expected resulting number is called a check digit, and it offers the most significant real life application of the Luhn Algorithm.
Check digits help to verify whether a set of numbers is accurate. An interesting fact about check digits is that the Luhn Algorithm determines them, not the credit card company. The algorithm does this based on the numbers preceding the check digit, which is usually printed as the last credit card digit.
Not only that, the Luhn Algorithm is also incorporated into code libraries and programming languages, thereby making it possible to integrate identification numbers in software applications.
Limitations of the Luhn Algorithm
One major limitation is that the Luhn Algorithm can only detect single digit errors, including transpositions of adjacent numbers. However, this isn’t the case for transpositions of the following sequence: “(first-valid-character)(last-valid-character)” to “(last-valid-character)(first-valid-character)” or vice versa.
What this means is, in the case of a 0 – 9 digit set, transpositions of the ‘09’ to ‘90’ or vice versa won’t be detected by the Luhn Algorithm.
Be that as it may, the algorithm enjoys wide acceptance particularly in finance, as it speeds up electronic payment processes and also makes them relatively easy.
We can help
Like the Luhn Algorithm, our automated payment services will speed up and make your electronic payment processing easier than you think. Find out how GoCardless can help you with adhoc payment or recurring payments.
GoCardless simplifie la collecte de paiements récurrents
Gagnez du temps en automatisant vos paiements récurrents en toute sérénité.