Link to home
Start Free TrialLog 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
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mahsa60

ASKER

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