An algorithm to validate a credit card number
Luhn Algorithm, or Modulus 10 Algorithm, is a mathematical formula that helps to determine whether or not a correct identification number has been provided.The Luhn algorithm helps to validate identification numbers, which explains why it’s widely used in electronic payment systems, most notably credit cards.Due to its ability to rapidly identify wrong card numbers, the algorithm typically speeds up electronic payment processing.
- Find the sum of odd index values of the credit card.
- Find the number of even numbers.
- Calculate the double of even numbers.
- Find sum of even numbers.
- Find sum of odd and even numbers if add up to the multiples of 10 then the credit card is valid
- can only detect single digit errors, including transpositions of adjacent numbers.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.