Link to home
Create AccountLog in
Avatar of Mahsa60
Mahsa60Flag for Iran, Islamic Republic of

asked on

RC4 encryption in delphi 7

hi
i founfd this two function to encrypt and decrypt a text in delphi 7
but when i use these functions , delphi doesn't know TDCP_rc4

what can i do ?


function RC4Encrypt(Data, Key: string): string;
var Encrypted: array of byte;
    i: integer;
begin
 result := '';

 with TDCP_rc4.Create(nil) do
 try
  Init(Key[1], Length(Key) * 8, nil);
  SetLength(Encrypted, Length(Data));
  Encrypt(Data[1], Encrypted[0], Length(Data));

  for i := 0 to Length(Encrypted) - 1 do
   result := result + IntToHex(Encrypted[i], 2);

  result := LowerCase(result);
 finally
  Free();
 end;
end;


function RC4Decrypt(Data, Key: string): string;
var Encrypted: array of byte;
    i: integer;
begin
 result := '';

 with TDCP_rc4.Create(nil) do
 try
  Init(Key[1], Length(Key) * 8, nil);

  SetLength(Encrypted, Length(Data) div 2);

  for i := 0 to Length(Encrypted) - 1 do
   Encrypted[i] := StrToInt('$' + Copy(Data, (i * 2) + 1, 2));

  SetLength(result, Length(Encrypted));
  Decrypt(Encrypted[0], result[1], Length(Encrypted));
 finally
  Free();
 end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var s: string;
begin
 s := RC4Encrypt('test string', '123456');
 s := RC4Decrypt(s, '123456');
end;
ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Mahsa60

ASKER

that was Your Codes , thank you .....