Aadhaar data needs to be treated securely. According to the RBI and Government of India mandate, organizations that collect and store identity details must mask the first 8 digits of the Aadhaar number and reveal only the last 4 for security and compliance. Whether it’s for government subsidies, income tax filing, or opening bank accounts, Aadhaar numbers must be validated and masked.
Aadhaar masking tools use Verhoeff algorithm, a checksum algorithm to validate, detect errors and ensure the integrity of the masked Aadhaar number. At M2P, we implemented Verhoeff algorithm on Flutter.
Our engineer, Nandhakumar Krishnan, delves deep into the step-by-step implementation of the Verhoeff algorithm in Flutter, which guarantees the authenticity of these crucial identification numbers.
Before we embark on the journey, it’s important to understand the relationship between Aadhaar numbers and Verhoeff algorithm.
Aadhaar Number and Verhoeff Algorithm
Aadhaar numbers are generated by the Unique Identification Authority of India (UIDAI) and are linked to an individual’s biometric and demographic information, including fingerprints, iris scans, and photographs. The Aadhaar number comprises 12 digits, out of which 11 digits are uniquely generated, and the last digit is the checksum.
The checksum is derived from the Verhoeff algorithm using a series of mathematical calculations. The result of these calculations is used to determine the appropriate checksum digit. By appending the checksum digit to the 11-digit portion of the Aadhaar number, the Verhoeff algorithm enables easy detection of errors or discrepancies that occurs during data entry or transmission. If any of the digits are altered, the resulting Aadhaar number will fail the checksum validation.
How to Implement the Verhoeff Algorithm?
To begin implementing check digit algorithms, it is necessary to create an abstract class as a foundation for the process. This abstract class will serve as a basis for incorporating the Verhoeff algorithm and its functionality within the code.
The abstract class
- In order to proceed, it is important to consider the multiplication table, permutation table, and the inverse table.
- This table is based on multiplication in the dihedral group D5 and is simply the Cayley table of the group.
Note: This group is not commutative, i.e., for some values of j and k, d(j,k) != d(k, j).
The multiplication table
- In the inverse table, ‘inv’ represents the multiplicative inverse of a digit, i.e., the value that satisfies d(j, inv(j)) = 0.
The inverse table
- In the permutation table, p applies a permutation to each digit based on its position in the number.
- This is a single permutation (1 5 8 9 4 2 7 0)(3 6) applied iteratively; i.e., p(i+j,n) = p(i, p(j,n)).
The permutation table
Next, we must compute the Verhoeff checksum formula.
Generating the checksum formula
The above snippet generates a checksum for the given Aadhaar number. The validate function then verifies that the checksum matches the last digit of the Aadhaar number. If they are the same, then the Aadhaar number is considered valid.
Implementing the Verhoeff Algorithm in Flutter
To implement the Verhoeff algorithm in your Flutter application, follow these steps:
Step 1: Import the Verhoeff algorithm class
Step 2: Validate and check the digit of the user provided Aadhaar number
Note: Ensure that the user inputs a number without any spaces or characters.
The Verhoeff algorithm computes the checksum and validates the input Aadhaar number.
If the computed checksum matches the last digit of the Aadhaar number, it means that the number is validated.
Indispensable Layer of Security
The Verhoeff algorithm prevents manual errors and ensures the integrity of Aadhaar numbers. This implementation adds an extra layer of protection and reliability when handling Aadhaar numbers, contributing to the overall authenticity of this vital identification system.
The use case of the algorithm is not limited to Aadhaar numbers alone. It can be used to validate credit card numbers, phone numbers, and product codes, making it an essential tool in today’s data-driven world.
Want to know about Aadhaar validation and masking?
Get in touch with us at firstname.lastname@example.org
Subscribe to our newsletter and get the latest fintech news, views, and insights, directly to your inbox.