Validating UIDAI Aadhaar number using Verhoeff Algorithm
If you are working on such application where you have to authenticate Aadhaar number entered by the user you may want to validate it using any standard algorithm before sending it to UIDAI server to get auth response. Before learning how to write code using Verhoeff algorithm let us understand about the structure of Aadhaar number issued by UIDAI(Unique Identification Authority of India).
Structure of Aadhaar Number :
The Aadhaar number has 12 digits numbers only where the first 11 digits are random numbers and the twelfth digit is a checksum (by using the Verhoeff algorithm) of the preceding 11 digits.
How to write code using Verhoeff algorithm :
The Verhoeff algorithm is basically a checksum formula for error detection which was first published in 1960 and developed by the Dutch mathematician Jacobus Verhoeff. It was the first decimal check digit algorithm which detects all single-digit errors, and all transposition errors involving two adjacent digits, which was at the time thought impossible with such a code.
For more info, you can navigate this link – https://en.wikipedia.org/wiki/Verhoeff_algorithm
- Multiplication Table D. The first table, d, is based on multiplication in the dihedral group D5
- The inverse table inv represents the multiplicative inverse of a digit.
- The permutation table p applies a permutation to each digit based on its position in the number.
When you try to understand the above code, you can easily understand this is not tough to bypass the algorithm if somebody actually knows how to find out checksum of the last 11 digits of their Aadhaar number. The sole purpose to use the Verhoeff algorithm to avoid silly data entry errors before sending it to the UIDAI server for real-time authentication.