The Verhoeff algorithm is a checksum formula for error detection developed by the Dutch mathematician Jacobus Verhoeff and was first published in 1969. 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.
Goals
Verhoeff had the goal of finding a decimal code—one where the check digit is a single decimal digit—which detected all single-digit errors and all transpositions of adjacent digits. At the time, supposed proofs of the nonexistence of these codes made base-11 codes popular, for example in the ISBN check digit. His goals were also practical, and he based the evaluation of different codes on live data from the Dutch postal system, using a weighted points system for different kinds of error. The analysis broke the errors down into a number of categories: first, by how many digits are in error; for those with two digits in error, there are transpositions, twins, jump transpositions, phonetic, and jump twins. Additionally there are omitted and added digits. Although the frequencies of some of these kinds of errors might be small, some codes might be immune to them in addition to the primary goals of detecting all singles and transpositions. The phonetic errors in particular showed linguistic effects, because in Dutch, numbers are typically read in pairs; and also while 50 sounds similar to 15 in Dutch, 80 doesn't sound like 18. Taking six-digit numbers as an example, Verhoeff reported the following classification of the errors:.
Description
Verhoeff devised his algorithm using the properties of the dihedral group of order 10, combined with a permutation. He claimed that it was the first practical use of the dihedral group, and confirmed the principle that in the end, all beautiful mathematics will find a use, even though in practice the algorithm will be implemented using simple lookup tables without needing to understand how to generate those tables from the underlying group and permutation theory. This is more properly considered a family of algorithms, as there are other permutations possible, and discussed in Verhoeff's treatment. He notes that this particular permutation, is special as it has the property of detecting 95.3% of the phonetic errors. The strengths of the algorithm are that it detects all transliteration and transposition errors, and additionally most twin, twin jump, jump transposition and phonetic errors. The main weakness of the Verhoeff algorithm is its complexity. The calculations required cannot easily be expressed as a formula. Lookup tables are required for easy calculation. A similar code is the Damm algorithm, which has similar qualities.
Table-based algorithm
The Verhoeff algorithm can be implemented using three tables: a multiplication tabled, an inverse table inv, and a permutation table p. The first table, d, is based on multiplication in the dihedral group D5. and is simply the Cayley table of the group. Note that this group is not commutative, that is, for some values of j and k, d ≠ d. The inverse table inv represents the multiplicative inverse of a digit, that is, the value that satisfies d = 0. The permutation table p applies a permutation to each digit based on its position in the number. This is actually a single permutation applied iteratively; i.e. p = p. The Verhoeff checksum calculation is performed as follows:
Create an array n out of the individual digits of the number, taken from right to left.
Initialize the checksum c to zero.
For each index i of the array n, starting at zero, replace c with d.
The original number is valid if and only ifc = 0. To generate a check digit, append a 0, perform the calculation: the correct check digit is inv.
Examples
Generate a check digit for 236:
i
ni
p
c
0
0
0
0
1
6
3
3
2
3
3
1
3
2
1
2
c is 2, so the check digit is inv, which is 3. Validate the check digit 2363: