Search



Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The first array contains the result of "Dihedral D5" multiplication;
  • The second array consists of 8 rows of which two are defined while the rest are derived by applying the following formula: F(i, j) = F(i - 1, F(1, j)) ;
  • The third array consists of a single row containing the inverse of the Dihedral D5 array it identifies the location of all the zero values in the first array.

 


Caption label
CapIdresults-of-dihedral-d5-multiplication
CapTypeTable
Results of Dihedral D5 multiplication

...



0

1

2

3

4

5

6

7

8

9

0

0

1

2

3

4

5

6

7

8

9

1

1

2

3

4

0

6

7

8

9

5

2

2

3

4

0

1

7

8

9

5

6

3

3

4

0

1

2

8

9

5

6

7

4

4

0

1

2

3

9

5

6

7

8

5

5

9

8

7

6

0

4

3

2

1

6

6

5

9

8

7

1

0

4

3

2

7

7

6

5

9

8

2

1

0

4

3

8

8

7

6

5

9

3

2

1

0

4

9

9

8

7

6

5

4

3

2

1

0


Caption label
CapIdthe-full-array-for-function-f
CapTypeTable
The full array for Function F

...



0

1

2

3

4

5

6

7

8

9

0

0

1

2

3

4

5

6

7

8

9

1

1

5

7

6

2

8

3

0

9

4

2

5

8

0

3

7

9

6

1

4

2

3

8

9

1

6

0

4

3

5

2

7

4

9

4

5

3

1

2

6

8

7

0

5

4

2

8

6

5

7

3

9

0

1

6

2

7

9

3

8

0

6

4

1

5

7

7

0

4

6

9

1

3

2

5

8


Caption label
CapIdthe-inverse-d5-array
CapTypeTable
The Inverse D5 array


0

1

2

3

4

5

6

7

8

9 


0

4

3

2

1

5

6

7

8

9 


The identifier is checked by starting at the rightmost digit of the identifier (the check-digit itself) and proceeding to the left processing each digit as follows:

...

Code Block
languagevb
themeEclipse
titleVisual Basic Code for Check-Digit Computation
collapsetrue
Option Explicit
Private Dihedral(9) As Variant
Private FnF(7) As Variant
Private InverseD5 As Variant
Public Function VerhoeffCheck(ByVal IdValue As String) As Boolean
'Check the supplied value and return true or false
Dim tCheck As Integer, i As Integer
VerhoeffArrayInit
For i = Len(IdValue) To 1 Step -1
tCheck = Dihedral(tCheck)(FnF((Len(IdValue) - i) Mod 8)(Val(Mid(IdValue, i, 1))))
Next
VerhoeffCheck = tCheck = 0
End Function
Public Function VerhoeffCompute(ByVal IdValue As String) As String
'Compute the check digit and return the identifier complete with check-digit
Dim tCheck As Integer, i As Integer
VerhoeffArrayInit
For i = Len(IdValue) To 1 Step -1
tCheck = Dihedral(tCheck)(FnF((Len(IdValue) - i + 1) Mod 8)(Val(Mid(IdValue, i, 1))))
Next
VerhoeffCompute = IdValue & InverseD5(tCheck)
End Function
Private Sub VerhoeffArrayInit()
'Create the arrays required
Dim i As Integer, j As Integer
'if already created exit here
If VarType(InverseD5) >= vbArray Then Exit Sub
'create the DihedralD5 array
Dihedral(0) = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Dihedral(1) = Array(1, 2, 3, 4, 0, 6, 7, 8, 9, 5)
Dihedral(2) = Array(2, 3, 4, 0, 1, 7, 8, 9, 5, 6)
Dihedral(3) = Array(3, 4, 0, 1, 2, 8, 9, 5, 6, 7)
Dihedral(4) = Array(4, 0, 1, 2, 3, 9, 5, 6, 7, 8)
Dihedral(5) = Array(5, 9, 8, 7, 6, 0, 4, 3, 2, 1)
Dihedral(6) = Array(6, 5, 9, 8, 7, 1, 0, 4, 3, 2)
Dihedral(7) = Array(7, 6, 5, 9, 8, 2, 1, 0, 4, 3)
Dihedral(8) = Array(8, 7, 6, 5, 9, 3, 2, 1, 0, 4)
Dihedral(9) = Array(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
'create the FunctionF array
FnF(0) = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
FnF(1) = Array(1, 5, 7, 6, 2, 8, 3, 0, 9, 4)
'compute the rest of the FunctionF array
For i = 2 To 7
FnF (i) = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
For j = 0 To 9
FnF (i)(j) = FnF(i - 1)(FnF(1)(j))
Next
Next
'Create the InverseD5 array
InverseD5 = Array("0", "4", "3", "2", "1", "5", "6", "7", "8", "9")
End Sub

...