Below is my origin python code that I got from someones' blog data. I guess it was written by Python 2.x
import os
def calcPassword(strHash):
salt = 'Iou|hj&Z'
pwd = ""
for i in range(0, 8):
b = ord(salt[i]) ^ ord(strHash[i])
a = b
c = 0x66666667 >> 32
a = (a * 0x66666667) >> 32
a = (a >> 2) | (a & 0xC0)
if ( a & 0x80000000 ):
a += 1
a *= 10
pwd += str(b-a)
return pwd
print("Master Password Generator for InsydeH2O BIOS (Acer, HP laptops)")
print("Copyright (C) 2009-2011 dogbert <[email protected]>")
print("")
print("Enter three invalid passwords. You will receive a hash code consisting")
print("out of eight numbers ")
print("e.g. 03133610")
print("")
print("Please enter the hash: ")
#inHash = raw_input().strip().replace('-', '')
inHash = '03133610'
password = calcPassword(inHash)
print("")
print("The master password is: " + password)
print("")
print("Please note that the password is encoded for US QWERTY keyboard layouts.")
if (os.name == 'nt'):
print("Press a key to exit...")
raw_input()
Now I am trying to migrate it from Python to Delphi. Below is my delphi code
function get_insyde_Password(strHash : string) : string;
const
salt = 'Iou|hj&Z';
var
pwd : string;
i : Byte;
a, b : Byte;
c : Cardinal;
begin
pwd := '';
for i in [0..8] do //for i in range(0, 8):
begin
b := ord(salt[i + 1]) xor ord(strHash[i + 1]); //b = ord(salt[i]) ^ ord(strHash[i])
a := b; //a = b
a := (a * $66666667) shr 32; //a = (a * 0x66666667) >> 32
a := (a shr 2) or (a and $C0); //a = (a >> 2) | (a & 0xC0)
if (a and $80000000) <> 0 then //if ( a & 0x80000000 ):
begin
Inc(a); //a += 1
end;
a := a * 10; //a *= 10
pwd := pwd + IntToStr(b-a); //pwd += str(b-a)
end;
Result := pwd;
end;
Of course above delphi code runs without any error. But the results of Python Interpreter and Delphi compiler don't show same value. What is my mistakes? I used Delphi XE2 version for it. Please point out my mistakes.... Thanks everyone.