What is the Verhoeff Algorithm?
The Verhoeff algorithm is a checksum formula used to validate identification numbers. It was developed by Dutch mathematician Jacobus Verhoeff in 1969 and is used by NIMC to ensure NIN integrity and detect input errors.
Why Use the Verhoeff Algorithm?
- • Detects all single-digit errors
- • Catches all transposition errors
- • Detects most other error types
- • More accurate than simple checksum
- • Nigerian NIN validation
- • Credit card numbers
- • Bank account numbers
- • Other identification systems
How It Works
Algorithm Steps
- Take the NIN digits from right to left
- Apply multiplication and permutation tables
- Calculate the checksum using dihedral group D5
- Verify the result equals zero for valid NIN
Mathematical Foundation
Multiplication Table
A 10x10 table based on the dihedral group D5 used for digit operations.
Permutation Table
Maps digits through different permutations based on position.
Inverse Table
Provides inverse values for the final validation step.
Implementation Example
// Simplified Verhoeff validation example
function verhoeffValidate(nin) {
const d = [
[0,1,2,3,4,5,6,7,8,9],
[1,2,3,4,0,6,7,8,9,5],
[2,3,4,0,1,7,8,9,5,6],
// ... multiplication table
];
const p = [
[0,1,2,3,4,5,6,7,8,9],
[1,5,7,6,2,8,3,0,9,4],
// ... permutation table
];
let c = 0;
const ninReversed = nin.split('').reverse();
for (let i = 0; i < ninReversed.length; i++) {
c = d[c][p[i % 8][parseInt(ninReversed[i])]];
}
return c === 0;
}Error Detection Capabilities
Single digit errors detected
Adjacent transposition errors
All other error types
Practical Applications
Real-time Validation
Used in web forms and applications to immediately detect invalid NINs before submitting to NIMC systems.
Data Quality Assurance
Helps maintain database integrity by preventing storage of invalid NINs.
User Experience
Provides immediate feedback to users about NIN entry errors.
Developer Note
While the Verhoeff algorithm can validate NIN format and checksum, it cannot verify if a NIN actually exists in the NIMC database. Always use it as a first-level validation before making API calls to official systems.