Solved

RC4 encryption in delphi 7

Posted on 2008-06-10
2
3,063 Views
Last Modified: 2010-04-21
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;
0
Comment
Question by:Mahsa60
2 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 125 total points
ID: 21750116
lol, it actually looks like code from me :) Where did you find it?

It probably uses DCPcrypt: http://www.cityinthesky.co.uk/cryptography.html
0
 

Author Closing Comment

by:Mahsa60
ID: 31465667
that was Your Codes , thank you .....
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now