Luhn’s Algorithmus, also known as the Luhn-Formel or Modulus-10-Algorithmus, is a simple checksum formula that is widely used to validate identification numbers, especially credit card numbers. Entwickelt von 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.
Der Algorithmus funktioniert nach den folgenden Schritten:
- Beginnen Sie mit der rechten Ziffer und verdoppeln Sie den Wert jeder zweiten Ziffer. Wenn diese Verdoppelung zu einer Zahl größer als 9 führt, subtrahieren Sie 9 vom Ergebnis.
- Addieren Sie alle Ziffern, sowohl die veränderten als auch die unveränderten.
- If the total modulo 10 is equal to 0, then the number is valid according to Luhn’s Algorithm.
Zum Beispiel, betrachten Sie die Nummer 4539 1488 0343 6467:
- Verdoppeln Sie jede zweite Ziffer von rechts: 4, 10, 3, 18, 8, 0, 3, 12, 6, 12, 7.
- Passen Sie diejenigen an, die größer als 9 sind: 4, 1, 3, 9, 8, 0, 3, 3, 6, 3, 7.
- Summe: 4 + 1 + 3 + 9 + 8 + 0 + 3 + 3 + 6 + 3 + 7 = 43.
- Überprüfen Sie, ob 43 modulo 10 gleich 0 ist: nein, also ist die Nummer ungültig.
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.