0% found this document useful (0 votes)
19 views

Luhnsalgorithm 241115182419 2a0387c4

Uploaded by

1mohamed.gamal54
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Luhnsalgorithm 241115182419 2a0387c4

Uploaded by

1mohamed.gamal54
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Luhn’s Algorithm

By Mohamed Gamal

© Mohamed Gamal 2024


Luhn’s algorithm
– The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10"
algorithm, named after its creator, IBM scientist Hans Peter Luhn, is a simple check digit
formula used to validate a variety of identification numbers.

– The algorithm is in the public domain and is in wide use today.

– Most credit cards and many government identification numbers use the algorithm as a
simple method of distinguishing valid numbers from mistyped or otherwise incorrect
numbers.

– We can validate Egyptian national IDs using Luhn's algorithm.

» The Egyptian national ID is a 14-digit number where the last digit is a checksum.
» The first 13 digits are used to calculate the checksum using Luhn's algorithm.

Hans Peter Luhn


Algorithm
1. Drop the check digit (last digit) of the number to validate.
2. Reverse the digits.
3. Double every second digit starting from the rightmost digit.
4. Calculate the sum of all digits.
5. Calculate the checksum (10 − (sum % 10)) % 10
6. Validate against the original checksum.
Example
National ID = 30201095501283

1) The checksum digit (last digit) is 3.

2) The first 13 digits are 3, 0, 2, 0, 1, 0, 9, 5, 5, 0, 1, 2, 8.

3) Reverse the digits: 8, 2, 1, 0, 5, 5, 9, 0, 1, 0, 2, 0, 3.

4) Double every second digit: 16, 2, 2, 0, 10, 5, 18, 0, 2, 0, 4, 0, 6.

5) Calculate the sum: 1 + 6 + 2 + 2 + 1 + 0 + 5 + 1 + 8 + 0 + 2 + 0 + 4 + 0 + 6 = 38.

6) The checksum is (10 - (38 % 10)) % 10 = 2.

7) The calculated checksum is 2, which mismatches the original checksum 3.

8) Therefore, the Egyptian national ID is invalid.


Python Code

You might also like