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.



									function CheckSum($number)
{
	$table = "0317598642709215486342068713591750983426612304597836742095815869720134894536201794386172052581436790";
	$interim = '0';
	$numLen = strlen($number);

	for ($i = 0; $i < $numLen; ++$i)
	{
		if (($number[$i] - '0') > 9)
			return '-';

		$interim = $table[($number[$i] - '0') + ($interim - '0') * 10];
	}

	return $interim;
}

function Validate($number)
{
	return CheckSum($number) == '0';
}
								


Example

									$c = CheckSum("572");
$isValid = Validate("5724");
								


Output

									c: 4
isValid: true