Je veux programmer le code source svp...

ammarallali - 20 mai 2013 à 12:23
sp40 Messages postés 1276 Date d'inscription mardi 28 octobre 2003 Statut Contributeur Derniè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;

const
SizeOfTeaBuffer = SizeOf(TTeaBuffer);
SizeOfTeaKey = SizeOf(TTeaKey);

procedure XTea_Bloc_Crypt(var V: TTeaBuffer; const K: TTeaKey);
procedure XTea_Bloc_Decrypt(var V: TTeaBuffer; const K: TTeaKey);

procedure XTea_Crypt(const Buffer, Key; const BufferSize, KeySize : integer; var Dest: pBytes);
procedure XTea_Decrypt(const Buffer, Key; const BufferSize, KeySize : integer; var Dest: pBytes);

function XTea_Crypt_Str(const Buffer, Key: AnsiString): AnsiString;
function XTea_Decrypt_Str(const Buffer, Key: AnsiString): AnsiString;


implementation

const
_DELTA = $9E3779B9;
_N = 32;

type
pArByte = ^ArByte;
ArByte = array[0..0] of byte;

procedure XTea_Bloc_Crypt(var V: TTeaBuffer; const K: TTeaKey);
var
I: LongWord;
S: Int64;
begin
S := 0;
for I := 0 to _N-1 do
begin
Inc(V[0], ((V[1] shl 4) xor (V[1] shr 5)) + (V[1] xor S) + K[S and 3]);
Inc(S, _DELTA);
Inc(V[1], ((V[0] shl 4) xor (V[0] shr 5)) + (V[0] xor S) + K[(S shr 11) and 3]);
end;
end;

procedure XTea_Bloc_Decrypt(var V: TTeaBuffer; const K: TTeaKey);
var
I: LongWord;
S: Int64;
begin
S := _DELTA * Int64(_N);
for I := 0 to _N-1 do
begin
Dec(V[1], ((V[0] shl 4) xor (V[0] shr 5)) + (V[0] xor S) + K[(S shr 11) and 3]);
Dec(S, _DELTA);
Dec(V[0], ((V[1] shl 4) xor (V[1] shr 5)) + (V[1] xor S) + K[S and 3]);
end;
end;

procedure XTea_Crypt(const Buffer, Key; const BufferSize, KeySize : integer; var Dest: pBytes);
var
pB, pK : pArByte;
V: TTeaBuffer;
K: TTeaKey;
I, L, N: Integer;
begin
pB := pArByte(Buffer);
pK := pArByte(Key);

L := KeySize;
if L > SizeOfTeaKey then
L := SizeOfTeaKey;

K[0] := 0;
K[1] := 0;
K[2] := 0;
K[3] := 0;
Move(pK^[0], K[0], L);

I := 1;
L := BufferSize;

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_Crypt(V, K);

Move(V[0], Dest^[I], SizeOfTeaBuffer);
Inc(I, SizeOfTeaBuffer);
end;
end;

procedure XTea_Decrypt(const Buffer, Key; const BufferSize, KeySize : integer; var Dest: pBytes);
var
pB, pK : pArByte;
V: TTeaBuffer;
K: TTeaKey;
I, L, N: Integer;
begin
pB := pArByte(Buffer);
pK := pArByte(Key);

L := KeySize;

if L > SizeOfTeaKey then
L := SizeOfTeaKey;

K[0] := 0;
K[1] := 0;
K[2] := 0;
K[3] := 0;
Move(pK^[0], K[0], L);

I := 1;
L := BufferSize;

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;

K[0] := 0;
K[1] := 0;
K[2] := 0;
K[3] := 0;
Move(Key[1], K[0], L);

I := 1;
L := Length(Buffer);

if L > 0 then
SetLength(Result, ((L-1) div SizeOfTeaBuffer+1) * SizeOfTeaBuffer)
else
SetLength(Result, 0);

while I <= L do
begin
V[0] := 0;
V[1] := 0;

N := L - I + 1;

if N > SizeOfTeaBuffer then
N := SizeOfTeaBuffer;

Move(Buffer[I], V[0], N);

XTea_Bloc_Crypt(V, K);

Move(V[0], Result[I], SizeOfTeaBuffer);
Inc(I, SizeOfTeaBuffer);
end;
end;

function XTea_Decrypt_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;

K[0] := 0;
K[1] := 0;
K[2] := 0;
K[3] := 0;
Move(Key[1], K[0], L);

I := 1;
L := Length(Buffer);
if L > 0 then
SetLength(Result, ((L-1) div SizeOfTeaBuffer+1) * SizeOfTeaBuffer)
else
SetLength(Result, 0);

while I <= L do
begin
V[0] := 0;
V[1] := 0;

N := L - I + 1;

if N > SizeOfTeaBuffer then
N := SizeOfTeaBuffer;

Move(Buffer[I], V[0], N);

XTea_Bloc_Decrypt(V, K);

Move(V[0], Result[I], SizeOfTeaBuffer);

Inc(I, SizeOfTeaBuffer)
end;
end;

end.

11 réponses

ammarallali
20 mai 2013 à 12:23
code source svp
0
dubois77 Messages postés 675 Date d'inscription jeudi 17 avril 2008 Statut Membre Dernière intervention 19 février 2019 14
21 mai 2013 à 08:05
je ne comprends pas bien ce que tu veux !
à priori ce que tu nous montre est déjà du code source Delphi
(je ne pas regardé ce qu'il fait)


Dubois77
site perso
0
cs_cantador Messages postés 4720 Date d'inscription dimanche 26 février 2006 Statut Modérateur Dernière intervention 31 juillet 2021 13
21 mai 2013 à 11:06
les voies de CS sont impénétrables..

cantador
0
ammarallali
21 mai 2013 à 21:22
svp aidez moi à le tradui
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ammarallali
21 mai 2013 à 21:23
[^^sad1][^^sad1][^^sad1][^^sad1][^^sad1]
0
dubois77 Messages postés 675 Date d'inscription jeudi 17 avril 2008 Statut Membre Dernière intervention 19 février 2019 14
22 mai 2013 à 08:03
à traduire quoi ? ce que tu donnes est déjà traduit en delphi !

Dubois77
site perso
0
sp40 Messages postés 1276 Date d'inscription mardi 28 octobre 2003 Statut Contributeur Dernière intervention 3 juillet 2015 15
22 mai 2013 à 09:33
C'est peut être traduit, mais... avec des bugs ????

Simon
0
ammarallali
22 mai 2013 à 15:26
Je suis désolé c'est ici MIS
0
ammarallali
22 mai 2013 à 15:26
Je veux que ce travail
0
ammarallali
22 mai 2013 à 15:27
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;
0
sp40 Messages postés 1276 Date d'inscription mardi 28 octobre 2003 Statut Contributeur Dernière intervention 3 juillet 2015 15
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

Simon
0
Rejoignez-nous