/*///////////////////////////////////////////////////////////////
Calculate GRID, PHP, 2010-12-10
GRID = A1 + 5 (Issuer Code element) + 10 (Release number) + 1 (Checkcode)
Artix, master@7masterov.ru, icq:53666599, skype:artixmaster
* Error in code? Nothing is perfect!
* Free source for free Linux, use it for free!
* Please, do not remove this comment!
///////////////////////////////////////////////////////////////*/
function genGRID($issuer='12345',$release='0123456789') {
$codes = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$acodes = str_split($codes);
$bcodes = array_flip($acodes);
$newcode = "A1".$issuer.$release;
$p = 36;
$n = $newcode;
for($j=1;$j<=strlen($n);$j++) {
$s = $p%37+$bcodes[$n{$j-1}];
$p = ($s%36==0?36:$s%36) * 2;
}
$s = 36-$p%37+1;
return $n.$acodes[$s];
}
function checkGRID($code) {
if (strlen($code)==18) {
$issuer = substr($code,2,5);
$release = substr($code,7,10);
$check = genGRID($issuer,$release);
return ($check==$code);
}
return false;
}
$x = genGRID();
echo checkGRID($x)? "$x correctn" : "$x incorrect!n";
Справочник алгоритмов v0.05 © 2007-2025 Igor Salnikov aka SunDoctor