SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Luhn’s Algorithm
By Mohamed Gamal
© Mohamed Gamal 2024
– 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.
Luhn’s algorithm
Hans Peter Luhn
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.
Algorithm
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.
Example
National ID = 30201095501283
Python Code

More Related Content

PDF
The First Mile – Edge and IoT Data Collection with Apache NiFi and MiNiFi
PPT
Warehousing dimension star-snowflake_schemas
PPTX
PDF
The Microservices Manifesto: How to Get More Out of the Development Lifecycle
PPT
Introduction to Natural Language Processing
PPTX
Where and when to use the Oracle Service Bus (OSB)
PDF
Natural language processing (Python)
PPTX
Treebank annotation
The First Mile – Edge and IoT Data Collection with Apache NiFi and MiNiFi
Warehousing dimension star-snowflake_schemas
The Microservices Manifesto: How to Get More Out of the Development Lifecycle
Introduction to Natural Language Processing
Where and when to use the Oracle Service Bus (OSB)
Natural language processing (Python)
Treebank annotation

What's hot (20)

DOCX
Natural language processing
PPT
PDF
API Trends & Use Cases
PPTX
Domain driven design
PPTX
HyperText Transfer Protocol (HTTP)
PPTX
What is ETL?
PPT
Multithreading Presentation
PDF
Natural language processing
PDF
Google Workspace DB클라우드오피스 그룹웨어 소개
PPT
introduction to natural language processing(NLP).ppt
PPTX
PPT
Database systems
PPT
Introduction to Web Programming - first course
PDF
Natural Language Processing (NLP)
PPT
Introduction to JavaScript
PPTX
Data warehouse testing
PPTX
Php.ppt
PPT
RDBMS vs NoSQL
Natural language processing
API Trends & Use Cases
Domain driven design
HyperText Transfer Protocol (HTTP)
What is ETL?
Multithreading Presentation
Natural language processing
Google Workspace DB클라우드오피스 그룹웨어 소개
introduction to natural language processing(NLP).ppt
Database systems
Introduction to Web Programming - first course
Natural Language Processing (NLP)
Introduction to JavaScript
Data warehouse testing
Php.ppt
RDBMS vs NoSQL
Ad

Similar to Luhn's algorithm to validate Egyptian ID numbers (12)

DOCX
Ece175 computer programming for engineering applications homework assignment ...
PPTX
Project sa Master's degree LUHN FORMULA.pptx
PPTX
Number Guessing Game using Artiifcal intelligence
PDF
Luhn algorithm
PPTX
Teaching Deck_Coding Algorithms_V2.3.pptx
PPTX
Teaching Deck_Coding Algorithms_V2.3.pptx
PDF
17 Jo P May 08
PPT
ch05-program-logic-indefinite-loops.ppt
PPTX
Pseudorandom number generators powerpoint
PDF
Artificial intelligence professor jinsong dong 2 august 2017
PPTX
PPT
Discrete math ppt
Ece175 computer programming for engineering applications homework assignment ...
Project sa Master's degree LUHN FORMULA.pptx
Number Guessing Game using Artiifcal intelligence
Luhn algorithm
Teaching Deck_Coding Algorithms_V2.3.pptx
Teaching Deck_Coding Algorithms_V2.3.pptx
17 Jo P May 08
ch05-program-logic-indefinite-loops.ppt
Pseudorandom number generators powerpoint
Artificial intelligence professor jinsong dong 2 august 2017
Discrete math ppt
Ad

More from Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt (20)

PDF
PDF
PDF
PDF
Understanding Convolutional Neural Networks (CNN)
PDF
Complier Design - Operations on Languages, RE, Finite Automata
PDF
Object Oriented Programming (OOP) using C++ - Lecture 5
PDF
Object Oriented Programming (OOP) using C++ - Lecture 2
PDF
Object Oriented Programming (OOP) using C++ - Lecture 1
PDF
Object Oriented Programming (OOP) using C++ - Lecture 3
PDF
Object Oriented Programming (OOP) using C++ - Lecture 4
Understanding Convolutional Neural Networks (CNN)
Complier Design - Operations on Languages, RE, Finite Automata
Object Oriented Programming (OOP) using C++ - Lecture 5
Object Oriented Programming (OOP) using C++ - Lecture 2
Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 3
Object Oriented Programming (OOP) using C++ - Lecture 4

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Classroom Observation Tools for Teachers
PPTX
Institutional Correction lecture only . . .
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
01-Introduction-to-Information-Management.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Computing-Curriculum for Schools in Ghana
PPTX
master seminar digital applications in india
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
RMMM.pdf make it easy to upload and study
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Classroom Observation Tools for Teachers
Institutional Correction lecture only . . .
2.FourierTransform-ShortQuestionswithAnswers.pdf
Anesthesia in Laparoscopic Surgery in India
01-Introduction-to-Information-Management.pdf
Insiders guide to clinical Medicine.pdf
Sports Quiz easy sports quiz sports quiz
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Computing-Curriculum for Schools in Ghana
master seminar digital applications in india
Renaissance Architecture: A Journey from Faith to Humanism
O7-L3 Supply Chain Operations - ICLT Program
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...

Luhn's algorithm to validate Egyptian ID numbers

  • 1. Luhn’s Algorithm By Mohamed Gamal © Mohamed Gamal 2024
  • 2. – 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. Luhn’s algorithm Hans Peter Luhn
  • 3. 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. Algorithm
  • 4. 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. Example National ID = 30201095501283