libhsplasma:
- Code: Select all
void plEncryptedStream::TeaDecipher(unsigned int* buf) {
unsigned int second = buf[1], first = buf[0], key = 0xC6EF3720;
for (int i=0; i<32; i++) {
second -= (((first >> 5) ^ (first << 4)) + first)
^ (fEKey[(key >> 11) & 3] + key);
key += 0x61C88647;
first -= (((second >> 5) ^ (second << 4)) + second)
^ (fEKey[key & 3] + key);
}
buf[0] = first;
buf[1] = second;
}
Mine:
- Code: Select all
procedure xTeaDecrypt(Input : TTeaArray; var Result : TTeaArray);
var
First,
Second : Cardinal;
I : Integer;
Key : Cardinal;
begin
First := Input[0];
Second := Input[1];
Key := $C6EF3720;
for I := 0 to 31 do
begin
Second := Second - (
(((First Shr 5) Xor (First Shl 4)) + First)
Xor (URUKey[(Key Shr 11) and 3] + Key)
);
Inc(Key,$61C88647);
First := First - (
(((Second Shr 5) Xor (Second Shl 4)) + Second)
Xor (URUKey[Key and 3] + Key)
);
end;
Result[0] := First;
Result[1] := Second;
end;
Whole unit:
- Code: Select all
unit xTea;
interface
type
TTeaArray = Array [0..1] of Cardinal;
const
URUKey : Array [0..3] of Cardinal = ($6c0a5452, $03827d0f, $3a170b92, $16db7fc2);
procedure xTeaDecrypt(Input : TTeaArray; var Result : TTeaArray);
function LoadxTeaFile(Filename : String) : String;
implementation
uses Windows, Math, SysUtils;
function TeaArrayToStr(Input : TTeaArray) : String;
var
Output : Array [0..7] of Char;
begin
CopyMemory(@Output[0],@Input[0],8);
Result := Output[0] + Output[1] + Output[2] + Output[3] + Output[4] + Output[5] + Output[6] + Output[7];
end;
procedure xTeaDecrypt(Input : TTeaArray; var Result : TTeaArray);
var
First,
Second : Cardinal;
I : Integer;
Key : Cardinal;
begin
First := Input[0];
Second := Input[1];
Key := $C6EF3720;
for I := 0 to 31 do
begin
Second := Second - ((((First Shr 5) Xor (First Shl 4)) + First) Xor (URUKey[(Key Shr 11) and 3] + Key));
Inc(Key,$61C88647);
First := First - ((((Second Shr 5) Xor (Second Shl 4)) + Second) Xor (URUKey[Key and 3] + Key));
end;
Result[0] := First;
Result[1] := Second;
end;
function LoadxTeaFile(Filename : String) : String;
var
H : Integer;
Size : Integer;
Input,
Output : TTeaArray;
begin
Result := '';
H := FileOpen(Filename,fmOpenRead);
Size := FileSeek(H,0,2);
FileSeek(H,12,0);
if Size > 8 then
Repeat
FileRead(H,Input[0],8);
xTeaDecrypt(Input,Output);
Result := Result + TeaArrayToStr(Output);
Dec(Size,8);
Until Size < 8;
FileClose(H);
end;