View Single Post
Old 06-17-2011, 03:50   #55 (permalink)
telip
Freak Poster
 
Join Date: Jan 2005
Location: France
Posts: 199
Member: 103520
Status: Offline
Thanks Meter: 17
PHP version

Just save it as mypage.php on your server and open it by
http://mysite/mypage.php?imei=xxxxxxxxxxxxxxxx

It's possible to make it shorter for example without the three loops
and the comments.
But more easy to understain as it for php novice


<?
//Code by Comdif-Telecom//

$imei=$_GET['imei'];

//remove 3 first digit
$a=substr($imei, 3);
echo 'Use 12 last IMEI digits: '.$a.'<br/>';

// make digit's sum starting with value 0 and make a loop for 13 time to increment the value
$sum=0;
for ($i=0;$i<12;$i++)
{
$x=substr($a, $i,1);
$sum= ($sum + $x);
}
//display the sum
echo 'Sum digits: '.$sum.'<br/>';

//make a loop to give a VAR value to eatch digit digits must be modulo of IMEI digit X Sum
for ($i=0;$i<12;$i++)
{
$x=(((substr($a, $i,1) * $sum)) % 10);
define("A".$i."", $x);
}

// Display the first magic string
echo 'FIRST - STEP: ';echo A0;echo A1;echo A2;echo A3;echo A4;echo A5;echo A6;echo A7;echo A8;echo A9;echo A10;echo A11;

// Function to replace some digits by other will be used later
function replace ($string) {
$table = array('1'=>'8', '2'=>'6', '3'=>'4', '4'=>'2', '5'=>'0', '6'=>'8', '7'=>'6', '8'=>'4', '9'=>'2', '0'=>'0');
return strtr($string, $table);
}

//make a loop to have all IMEI digits defined as a VAR
for ($i=0;$i<12;$i++)
{ $z=substr($a, $i,1);
define("B".$i."", $z);
}

//To display the second magic string need to use the function replace and order them starting with the last
echo '<br/>Second- STEP: ';
echo replace(B11);echo replace(B10);echo replace(B9);echo replace(B8);echo replace(B7);echo replace(B6);echo replace(B5);echo replace(B4);echo replace(B3);
echo replace(B2);echo replace(B1);echo replace(B0);

//This is the magic constant number
echo '<br/>Magic- number: 688950000000';

//OK calculate NCK with sum modulo of the three strings
echo'<div align=center>
<strong>NCK/NP Code -
'.((A0 + replace(B11) + 6) % 10).'
'.((A1 + replace(B10) + 8) % 10).'
'.((A2 + replace(B9) + 8) % 10).'
'.((A3 + replace(B8) + 9) % 10).'
'.((A4 + replace(B7) + 5) % 10).'
'.((A5 + replace(B6) + 0) % 10).'
'.((A6 + replace(B5) + 0) % 10).'
'.((A7 + replace(B4) + 0) % 10).'
'.((A8 + replace(B3) + 0) % 10).'
'.((A9 + replace(B2) + 0) % 10).'
'.((A10 + replace(B1) + 0) % 10).'
'.((A11 + replace(B0) + 0) % 10).'</strong></div>';

echo'<br/><div align=center><strong><a href='.$_SERVER['PHP_SELF'].'>Go Back</a></strong></div>';
?>
  Reply With Quote
 
Page generated in 0.10269 seconds with 8 queries