Hallo,
Versuche ein Python Script auf PHP umzuschreiben.. Nur leider mach ich irgendwo ein Fehler das ich kein Ergebnis erhalte.
PYTHON
PHP umgeschrieben
Versuche ein Python Script auf PHP umzuschreiben.. Nur leider mach ich irgendwo ein Fehler das ich kein Ergebnis erhalte.
PYTHON
Code:
#!/bin/sh
import md5
def calCode(imei):
imeiMD5 = md5.new(imei).digest() # Get binary md5 hash of IMEI number
unlockCode = ""
for i in range(0, 8):
magicalSum = (ord(imeiMD5[i]) + ord(imeiMD5[i+8])) & 0xFF # Get last byte of two md5 byte sum
unlockCode += str((magicalSum * 9) / 255)
return unlockCode
def imeiCorrect(imei):
if (len(imei) != 15) or (not imei.isdigit()):
return False
else:
return True
if __name__ == '__main__':
imei = raw_input('IMEI: ')
if imeiCorrect(imei):
print 'NCK:', calCode(imei)
else:
print 'Incorrect IMEI!'
PHP-Code:
$imei = htmlspecialchars($_POST['imei']);
function calCode($imei)
{
$imeiMD5 = md5($imei);
$unlockCode = "";
for($i=0;$i<8;$i++)
{
$magicalSum = (ord($imeiMD5[$i]) + ord($imeiMD5[$i+8])) & 0xFF; # Get last byte of two md5 byte sum
$unlockCode += str(($magicalSum * 9) / 255);
}
return $unlockCode;
}
if(strlen($imei) == 15){
$imei = htmlspecialchars($imei);
echo "Unlock ". $unlockCode;
}
else{
if($imei < 15 && $imei > 1) {
echo "Error : Invalid IMEI";
}
}
echo "
<form method='post' action=''>
IMEI : <input type='text' name='imei' maxlength='15'><br>
<input type='submit' value='do it!'>
</form>";
Kommentar