Verhoeff algorithm
The Verhoeff algorithm^{[1]} is a checksum for error detection first published by Dutch mathematician Jacobus Verhoeff in 1969.^{[2]}^{[3]} It was the first decimal check digit algorithm which detects all singledigit errors, and all transposition errors involving two adjacent digits,^{[4]} which was at the time thought impossible with such a code. The method was independently discovered by H. Peter Gumm in 1985, this time including a formal proof and an extension to any base.^{[5]}
Goals
Verhoeff had the goal of finding a decimal code—one where the check digit is a single decimal digit—which detected all singledigit errors and all transpositions of adjacent digits. At the time, supposed proofs of the nonexistence^{[6]} of these codes made base11 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 (ab → ba), twins (aa → 'bb'), jump transpositions (abc → cba), phonetic (1a → a0), and jump twins (aba → cbc). 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 sixdigit numbers as an example, Verhoeff reported the following classification of the errors:.
Digits in error  Classification  Count  Frequency 

1  Transcription  9,574  79.05% 
2  Transpositions  1,237  10.21% 
Twins  67  0.55%  
Phonetic  59  0.49%  
Other adjacent  232  1.92%  
Jump transpositions  99  0.82%  
Jump Twins  35  0.29%  
Other jump errors  43  0.36%  
Other  98  0.81%  
3  169  1.40%  
4  118  0.97%  
5  219  1.81%  
6  162  1.34%  
Total  12,112 
Description
The general idea of the algorithm is to represent each of the digits (0 through 9) as elements of the dihedral group [math]\displaystyle{ D_5 }[/math]. That is, map digits to [math]\displaystyle{ D_5 }[/math], manipulate these, then map back into digits. Let this mapping be [math]\displaystyle{ m: [0, 9] \to D_5 }[/math]
[math]\displaystyle{ m = \begin{pmatrix} 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\ e & r & r^2 & r^3 & r^4 & s & rs & r^2s & r^3s & r^4s\end{pmatrix} }[/math]
Let the nth digit be [math]\displaystyle{ a_n }[/math] and let the number of digits be [math]\displaystyle{ k }[/math].
For example given the code 248 then [math]\displaystyle{ k }[/math] is 3 and [math]\displaystyle{ a_3 = m(8) = r^{3}s }[/math].
Now define the permutation [math]\displaystyle{ f: D_5 \to D_5 }[/math]
[math]\displaystyle{ f = \begin{pmatrix} e & r & r^2 & r^3 & r^4 & s & rs & r^2s & r^3s & r^4s\\ r & s & r^2s & rs & r^2 & r^3s & r^3 & e & r^4s & r^4\end{pmatrix} }[/math]
For example [math]\displaystyle{ f(r^3) = rs }[/math]. Another example is [math]\displaystyle{ f^2(r^3) = r^3 }[/math] since [math]\displaystyle{ f(f(r^3)) = f(rs) = r^3 }[/math]
Using multiplicative notation for the group operation of [math]\displaystyle{ D_5 }[/math], the check digit is then simply a value [math]\displaystyle{ c }[/math] such that
[math]\displaystyle{ f(a_1) \cdot f^2(a_2) \cdot \ldots \cdot f^k(a_k) \cdot f^{k+1}(c) = e }[/math]
[math]\displaystyle{ c }[/math] is explicitly given by inverse permutation
[math]\displaystyle{ c = f^{1k}\left(\prod_{n=1}^k f^n(a_n)^{1}\right) }[/math]
For example the check digit for 248 is 5. To verify this, use the mapping to [math]\displaystyle{ D_5 }[/math] and insert into the LHS of the previous equation
[math]\displaystyle{ f(r^2) \cdot f^2(r^4) \cdot f^3(r^3s) \cdot f^4(s) = e }[/math]
To evaluate this permutation quickly use that
[math]\displaystyle{ f^4(s) = f^3(r^3s) = f^2(r^4) = f(r^2) = r^2 s }[/math]
to get that
[math]\displaystyle{ r^2 s \cdot r^2 s \cdot r^2 s \cdot r^2 s = e }[/math]
This is the same reflection being iteratively multiplied. Use that reflections are their own inverse.^{[7]}
[math]\displaystyle{ (r^2 s \cdot r^2 s) \cdot (r^2 s \cdot r^2 s) = e^2 = e }[/math]
In practice the algorithm is 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 other permutations work too. Verhoeff's notes that the particular permutation, given above, is special as it has the property of detecting 95.3% of the phonetic errors.^{[8]}
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 in say [math]\displaystyle{ {\displaystyle \mathbb {Z} /10\mathbb {Z} } }[/math]. Lookup tables are required for easy calculation. A similar code is the Damm algorithm, which has similar qualities.
Tablebased algorithm
The Verhoeff algorithm can be implemented using three tables: a multiplication table d, an inverse table inv, and a permutation table p.



The first table, d, is based on multiplication in the dihedral group D_{5}.^{[7]} 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(j,k) ≠ d(k, j).
The inverse table inv represents the multiplicative inverse of a digit, that is, the value that satisfies d(j, inv(j)) = 0.
The permutation table p applies a permutation to each digit based on its position in the number. This is actually 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 Verhoeff checksum calculation is performed as follows:
 Create an array n out of the individual digits of the number, taken from right to left (rightmost digit is n_{0}, etc.).
 Initialize the checksum c to zero.
 For each index i of the array n, starting at zero, replace c with [math]\displaystyle{ d(c, p(i \bmod 8, n_i)) }[/math].
The original number is valid if and only if [math]\displaystyle{ c = 0 }[/math].
To generate a check digit, append a 0, perform the calculation: the correct check digit is [math]\displaystyle{ inv(c) }[/math].
Examples
Generate a check digit for 236:
c is 2, so the check digit is inv(2), which is 3. 
Validate the check digit 2363:
c is zero, so the check is correct. 
See also
 Luhn algorithm, earlier (1960) check digit algorithm
References
 ↑ Verhoeff, J. (1969). Error Detecting Decimal Codes (Tract 29). The Mathematical Centre, Amsterdam. doi:10.1002/zamm.19710510323. Bibcode: 1971ZaMM...51..240N.
 ↑ Kirtland, Joseph (2001). "5. Group Theory and the Verhoeff Check Digit Scheme". Identification Numbers and Check Digit Schemes. Mathematical Association of America. p. 153. ISBN 0883857200. https://books.google.com/books?id=npTxORxmLosC&pg=PA121.
 ↑ Salomon, David (2005). "§2.11 The Verhoeff Check Digit Method". Coding for Data and Computer Communications. Springer. pp. 56–58. ISBN 0387212450. https://books.google.com/books?id=A88kvYwIVu0C&pg=PA57.
 ↑ Haunsperger, Deanna; Kennedy, Stephen, eds (2006). The Edge of the Universe: Celebrating Ten Years of Math Horizons. Mathematical Association of America. p. 38. ISBN 9780883855553. https://books.google.com/books?id=jiaIeCUpoFwC&pg=PA39.
 ↑ Gumm, H. (January 1985). "A new class of checkdigit methods for arbitrary number systems (Corresp.)". IEEE Transactions on Information Theory 31 (1): 102–105. doi:10.1109/TIT.1985.1056991. https://www.researchgate.net/publication/3084126.
 ↑ Sisson, Roger L. (May 1958). "An improved decimal redundancy check". Communications of the ACM 1 (5): 10–12. doi:10.1145/368819.368854.
 ↑ ^{7.0} ^{7.1} Gallian, Joseph A. (2010). Contemporary Abstract Algebra (7th ed.). Brooks/Cole. p. 111. ISBN 9780547165097. https://archive.org/details/contemporaryabst00gall_1. Retrieved August 26, 2011. "verhoeff check digit."
 ↑ Verhoeff 1969, p. 95
 ↑ Verhoeff 1969, p. 83
External links
Original source: https://en.wikipedia.org/wiki/Verhoeff algorithm.
Read more 