Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/c327781/sibertec.com/index.php:1) in drupal_send_headers() (line 1485 of /hsphere/local/home/c327781/sibertec.com/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/c327781/sibertec.com/index.php:1) in drupal_send_headers() (line 1485 of /hsphere/local/home/c327781/sibertec.com/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/c327781/sibertec.com/index.php:1) in drupal_send_headers() (line 1485 of /hsphere/local/home/c327781/sibertec.com/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/c327781/sibertec.com/index.php:1) in drupal_send_headers() (line 1485 of /hsphere/local/home/c327781/sibertec.com/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/c327781/sibertec.com/index.php:1) in drupal_send_headers() (line 1485 of /hsphere/local/home/c327781/sibertec.com/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/c327781/sibertec.com/index.php:1) in drupal_send_headers() (line 1485 of /hsphere/local/home/c327781/sibertec.com/includes/bootstrap.inc).

A VB.Net Implementation of Verhoeff's Error Detection

I recently worked on a project that sent a dataset to a web service and received a confirmation code that used Verhoeff's decimal error detection to verify that the code was received without any errors.

I don't pretend to have any idea how it works, but it does. This implementation places the check digit at the beginning of the code string (YXXXXXXXXX - where Y is the check digit).

The VB.Net class module was adapted from Java code obtained from http://www.cs.utsa.edu/~wagner/laws/AVerhoeffErrorDetection.html.

This is the code for the class module:


'************************************************************** 
'* VerhoeffErrorDetection.vb 
'* 
'* Created 13 APR 2006 by Phillip Hopper 
'* 
'* Adapted from http://www.cs.utsa.edu/~wagner/laws/AVerhoeffErrorDetection.html 
'* 
'************************************************************** 

Public Class VerhoeffErrorDetection 

  Private op(,) As Integer = {{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}, _
    {3, 4, 0, 1, 2, 8, 9, 5, 6, 7}, _ 
    {4, 0, 1, 2, 3, 9, 5, 6, 7, 8}, _
    {5, 9, 8, 7, 6, 0, 4, 3, 2, 1}, _ 
    {6, 5, 9, 8, 7, 1, 0, 4, 3, 2}, _
    {7, 6, 5, 9, 8, 2, 1, 0, 4, 3}, _ 
    {8, 7, 6, 5, 9, 3, 2, 1, 0, 4}, _
    {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}} 

  Private inv() As Integer = {0, 4, 3, 2, 1, 5, 6, 7, 8, 9} 
  Private F(8, 10) As Integer 
  Private F0() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} 
  Private F1() As Integer = {1, 5, 7, 6, 2, 8, 3, 0, 9, 4} 

  Public Sub New() 

    Dim i As Integer, j As Integer 

    For i = 0 To 9 
      F(0, i) = F0(i) 
      F(1, i) = F1(i) 
    Next 

    For i = 2 To F.GetUpperBound(0) 
      For j = 0 To F.GetUpperBound(1) 
        F(i, j) = F(i - 1, F(1, j)) 
      Next 
    Next 

  End Sub 

  Public Function insertCheck(ByRef a() As Integer) As Integer 

    Dim check As Integer = 0 
    Dim i As Integer 

    For i = 1 To a.GetUpperBound(0) 
      check = op(check, F(i Mod 8, a(i))) 
    Next 

    a(0) = inv(check) 

    Return a(0) 

  End Function 

  Public Function doCheck(ByRef a() As Integer) As Boolean 

    Dim check As Integer = 0 
    Dim i As Integer 

    For i = 0 To a.GetUpperBound(0) 
      check = op(check, F(i Mod 8, a(i))) 
    Next 

    If check = 0 Then Return True Else Return False 

  End Function 

  Public Function doCheck(ByRef pCode As String) As Boolean 

    Dim s As String = String.Empty 
    Dim i As Integer 

    ' remove all num-numeric characters 
    For i = 0 To pCode.Length - 1 
      If IsNumeric(pCode.Substring(i, 1)) Then 
        s &= pCode.Substring(i, 1) 
      End If 
    Next 

    ' initialize the integer array 
    Dim a(s.Length - 1) As Integer 

    For i = 0 To s.Length - 1 
      a(i) = CInt(s.Substring(i, 1)) 
    Next 

    ' check the validity 
    Return doCheck(a) 

  End Function 

End Class 

To use the class, I am using this code:


' validate check digit 
Dim ved As VerhoeffErrorDetection = New VerhoeffErrorDetection 
If ved.doCheck(cd) Then .... 

The class can also calculate the check digit if you call insertCheck().