L

Luhn’s Algorithm

Luhn's Algorithm is a checksum formula used to validate identification numbers, particularly credit card numbers.

Luhn’s Algorithm, also known as the Luhn formula or modulus 10 algorithm, is a simple checksum formula that is widely used to validate identification numbers, especially credit card numbers. Developed by IBM scientist Hans Peter Luhn in 1954, this algorithm helps to prevent accidental errors in data entry and is employed by various industries to ensure the integrity of numeric identifiers.

The algorithm works by performing the following steps:

  1. Starting from the rightmost digit, double the value of every second digit. If this doubling results in a number greater than 9, subtract 9 from the result.
  2. Sum all the digits, both altered and unaltered.
  3. If the total modulo 10 is equal to 0, then the number is valid according to Luhn’s Algorithm.

For example, consider the number 4539 1488 0343 6467:

  • Double every second digit from the right: 4, 10, 3, 18, 8, 0, 3, 12, 6, 12, 7.
  • Adjust those greater than 9: 4, 1, 3, 9, 8, 0, 3, 3, 6, 3, 7.
  • Sum: 4 + 1 + 3 + 9 + 8 + 0 + 3 + 3 + 6 + 3 + 7 = 43.
  • Check if 43 modulo 10 equals 0: it does not, so the number is invalid.

Luhn’s Algorithm is particularly useful because it can be easily implemented and is effective in detecting simple errors, such as mistyped digits or transposed numbers. However, it’s important to note that while Luhn’s Algorithm can indicate that a number might be valid, it does not guarantee that the number is legitimate or has not been compromised.

Ctrl + /