Damm Algorithm

In error detection, the Damm algorithm is a check digit algorithm that detects all single-digit errors and all adjacent transposition errors. It was presented by H. Michael Damm in 2004. Its essential part is a quasigroup of order 10 (i.e. having a 10×10 Latin square as operation table) with the special feature of being totally anti-symmetric. Damm revealed several methods to create such TA-quasigroups of order 10 and gave some examples in his doctoral dissertation. With this, Damm also disproved an old conjecture that TA-quasigroups of order 10 do not exist.



									Public Shared Function CheckSum(number As String) As Char
	Const table As String = "0317598642709215486342068713591750983426612304597836742095815869720134894536201794386172052581436790"
	Dim interim As Char = "0"c

	For i As Integer = 0 To number.Length - 1
		If (Convert.ToByte(number(i)) - 48) > 9 Then
			Return "-"c
		End If

		interim = table((Convert.ToByte(number(i)) - 48) + (Convert.ToByte(interim) - 48) * 10)
	Next

	Return interim
End Function

Public Shared Function Validate(number As String) As Boolean
	Return CheckSum(number) = "0"c
End Function
								


Example

									Dim c As Char = CheckSum("572")
Dim isValid As Boolean = Validate("5724")
								


Output

									c: 4
isValid: True