"X" : ($total % 11); }

Kod źródłowy w PHP

function calcVINcheckdigit($vin){ //Uppercase to avoid errors $vin = strtoupper($vin);

//$cv is the "converted value" of any digit $cv = array('A'=>1,'B'=>2,'C'=>3,'D'=>4,'E'=>5,'F'=>6,'G'=>7,'H'=>8,'J'=>1, 'K'=>2,'L'=>3,'M'=>4,'N'=>5,'P'=>7,'R'=>9,'S'=>2,'T'=>3,'U'=>4, 'V'=>5,'W'=>6,'X'=>7,'Y'=>8,'Z'=>9,'0'=>0,'1'=>1,'2'=>2,'3'=>3, '4'=>4,'5'=>5,'6'=>6,'7'=>7,'8'=>8,'9'=>9);

//$multiplier is the number to multiply each digit by. $multiplier = array(8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2);

$total = 0; for ($i=0; $i<17; ++$i) { $total += $cv[$vin[$i]] * $multiplier[$i];

//The idea is to get the remainder of $total/11 //The remainder can be 0-10. 0-9 are their digits, and 10=X return ($total%11 == 10)? 'X':($total%11); }

Kod źródłowy w Ruby

# assumes that the vin string has already been validated to prevent # the submission of case-insensitive letters I, O and Q. Otherwise # nil errors will be thrown when searching the letter_value hash. def is_checkdigit_valid