ammarallali
-
20 mai 2013 à 12:23
sp40
Messages postés1276Date d'inscriptionmardi 28 octobre 2003StatutContributeurDernière intervention 3 juillet 2015
-
22 mai 2013 à 15:40
svp aidez moi à le tradui
code de c++ vers delphi
Je veux programmer le code source svp...
unit XTeaCrypt;
interface
uses Windows, SysUtils;
type
pBytes = ^Bytes;
Bytes = array of byte;
pTeaBuffer = ^TTeaBuffer;
TTeaBuffer = array[0..1] of LongWord;
pTeaKey = ^TTeaKey;
TTeaKey = array[0..3] of LongWord;
if L > 0 then
SetLength(Dest^, ((L-1) div SizeOfTeaBuffer+1) * SizeOfTeaBuffer)
else
exit;
while I <= L do
begin
V[0] := 0;
V[1] := 0;
N := L - I + 1;
if N > SizeOfTeaBuffer then
N := SizeOfTeaBuffer;
Move(pB^[I], V[0], N);
XTea_Bloc_Decrypt(V, K);
Move(V[0], Dest^[I], SizeOfTeaBuffer);
Inc(I, SizeOf(V))
end;
end;
function XTea_Crypt_Str(const Buffer, Key: AnsiString): AnsiString;
var
V: TTeaBuffer;
K: TTeaKey;
I, L, N: Integer;
begin
L := Length(Key);
if L > SizeOfTeaKey then
L := SizeOfTeaKey;
var
MaincodeTab : array of byte;
FPKEYDATA:array[0..15] of byte;
function GetLongword(adr:longword):longword;
begin
Result:=MaincodeTab[adr+3] shl 24+MaincodeTab[adr+2] shl 16 + MaincodeTab[adr+1] shl 8 + MaincodeTab[adr];
end;
function GetKeyLongword(adr:longword):longword;
begin
Result:=FPKEYDATA[adr+3] shl 24+FPKEYDATA[adr+2] shl 16 + FPKEYDATA[adr+1] shl 8 + FPKEYDATA[adr];
end;
procedure WriteLongword(adr,value:longword);
begin
MaincodeTab[adr+3]:=value shr 24;
MaincodeTab[adr+2]:=(value and $FF0000) shr 16;
MaincodeTab[adr+1]:=(value and $FF00) shr 8;
MaincodeTab[adr]:=(value and $FF);
end;
procedure XTEA_Decipher(ptr:longword);
var v0,v1,delta,sum,i,k1,k2:longword;
begin
v0 := GetLongword(ptr);
v1 := GetLongword(ptr+4);
delta:=$9E3779B9;
sum := 32 * delta;
for i:=0 to 31 do
begin
k1:=GetKeyLongword((sum shr 9) and $C);
v1 := v1 - ((((v0 shl 4) xor (v0 shr 5)) + v0) xor (sum + k1));
sum := sum - delta;
k2:= GetKeyLongword((sum and 3) shl 2);
v0 := v0 - ((((v1 shl 4) xor (v1 shr 5)) + v1) xor (sum + k2));
end;
WriteLongword(ptr,v0);
WriteLongword(ptr+4,v1);
end;
procedure XTEA_Bloc_Decipher(len_data_crypted:longword);
var maincode_ptr,maincode_ptr_end,j,i:longword;
begin
// on se place sur le dernier bloc
maincode_ptr := (len_data_crypted - 8) and $FFFFFFF8; // aligner sur 8 octets
if ((len_data_crypted / 8) <> 0) then
begin
for i := 0 to round(int(len_data_crypted/8))-1 do
begin
maincode_ptr_end := (len_data_crypted) - 8; // dernier bloc
if (maincode_ptr <> 0) then // ? est-on au premier bloc
maincode_ptr_end := maincode_ptr - 8; // si non, on prend le bloc précédent
for j := 0 to 7 do
MaincodeTab[maincode_ptr + j] := MaincodeTab[maincode_ptr + j] xor MaincodeTab[maincode_ptr_end + j];
XTEA_Decipher(maincode_ptr);
maincode_ptr := maincode_ptr - 8;
end;
end;
XTEA_Decipher(len_data_crypted - 8); // Decrypt le dernier bloc
end;
sp40
Messages postés1276Date d'inscriptionmardi 28 octobre 2003StatutContributeurDernière intervention 3 juillet 201515 22 mai 2013 à 15:40
Je ne comprends rien. Qu'est-ce que c'est que ce code ???
Qu'est ce que tu attends de nous ???
Quel est le problème ???
Fais un effort, expliques toi mieux ou trouve un site dans ta langue maternelle