#!/usr/bin/perl require "setup.pl"; &ReadParse(*input); print "Content-type: text/html\n\n"; print "\n\nOnline Proxy Voting Login\n\n"; print "\n"; if($input{"proxynum"} ne "") { $checkd = &CheckSum ($input{"proxynum"}.$input{"proxynum2"}.$input{"proxynum4"}); print "Full Value is ".$input{"proxynum"}." ".$input{"proxynum2"}." ".$input{"proxynum3"}." ".$input{"proxynum4"}." first digits of PIN should be ".$checkd."
\n"; } print "
\n"; print "Number:\n"; print "#"; print "#"; print "\n"; print "\n"; print "
\n"; sub CheckSum { ($numstring) = @_; $total = 0; $nslength = length($numstring); #go through each character of the string for($i = $nslength-1; $i >= 0; $i--) { if(($nslength - $i) % 2 == 0) { $thisval = substr($numstring,$i,1); } else { #some numbers get multiplied by two. if so, the result might be a two digit number. Those digits are added in seperately $thisval = substr($numstring,$i,1) * 2; if($thisval >= 10) { $thisval = $thisval - 10; $thisval = $thisval + 1; } } $total = $total + $thisval; } $checkone = $total % 10; $newstring = $numstring.$checkone; $total = 0; $nslength = length($newstring); for($i = $nslength-1; $i >= 0; $i--) { if(($nslength - $i) % 2 == 0) { $thisval = substr($newstring,$i,1); } else { #some numbers get multiplied by two. if so, the result might be a two digit number. Those digits are added in seperately $thisval = substr($newstring,$i,1) * 2; if($thisval >= 10) { $thisval = $thisval - 10; $thisval = $thisval + 1; } } $total = $total + $thisval; } $checktwo = $total % 10; $checkone.$checktwo; }