Fast Encryption

hello,
I need a code for a fast encryption
I mean I want to encrypt like 200 files, and I need to do it quickly
all the codes are very slow...
deathman5Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JaccoCommented:
How good does the encryption need to be?

Generally the better the encryption the slower the routine will be.

When the encryption security can be low very fast methods can be created.

For example you could only invert the data using the following code:

type
  TEncryptionStream = class(TStream)
  private
    fStream: TStream;
  public
    constructor Create(const aTargetStream: TStream);
    function Write(const Buffer; Count: Longint): Longint; override;
  end;

{ TEncryptionStream }

constructor TEncryptionStream.Create(const aTargetStream: TStream);
begin
  fStream := aTargetStream;
end;

function TEncryptionStream.Write(const Buffer; Count: Integer): Longint;
var
  lBuffer: string;
  liChar: Integer;
begin
  Result := Count;
  SetLength(lBuffer, Result);
  Move(Buffer, PChar(@lBuffer[1])^, Result);
  for liChar := 1 to Length(lBuffer) do
    if lBuffer[liChar] < #128 then
      lBuffer[liChar] := Chr(Ord(lBuffer[liChar]) + 128)
    else
      lBuffer[liChar] := Chr(Ord(lBuffer[liChar]) - 128);
  fStream.Write(Pointer(lBuffer)^, Result);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  lSS, lTS: TFileStream;
  lES: TEncryptionStream;
  t: TDateTime;
begin
  t := Now;
  lSS := TFileStream.Create('file1', fmOpenRead);
  try
    lTS := TFileStream.Create('tst', fmCreate);
    try
      lES := TEncryptionStream.Create(lTS);
      try
        lES.CopyFrom(lSS, lSS.Size);
      finally
        lES.Free;
      end;
    finally
      lTS.Free;
    end;
  finally
    lSS.Free;
  end;
  Memo1.Lines.Add(FormatDateTime('ss:zzz', Now -t));
end;

This encodes a 365KB file in just 0.031 seconds.

Let me know if you need the code for the decryption stream as well.

Regards Jacco

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
deathman5Author Commented:
yea plz give me the decryption code
aikimarkCommented:
Have you tried TurboPower Lockbox?
http://sourceforge.net/projects/tplockbox
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

JaccoCommented:
Here is the decompression part.

I also use tplockbox but do not now how well it performs.

Regards Jacco

type
  TDecompressionStream = class(TStream)
  private
    fStream: TStream;
  public
    constructor Create(const aTargetStream: TStream);
    function Read(var Buffer; Count: Longint): Longint; override;
  end;

{ TDecryptionStream }

constructor TDecompressionStream.Create(const aTargetStream: TStream);
begin
  fStream := aTargetStream;
end;

function TDecompressionStream.Read(var Buffer; Count: Integer): Longint;
var
  lBuffer: string;
  liChar: Integer;
begin
  Result := fStream.Read(Buffer, Count);
  SetLength(lBuffer, Result);
  Move(Buffer, PChar(@lBuffer[1])^, Result);
  for liChar := 1 to Length(lBuffer) do
    if lBuffer[liChar] < #128 then
      lBuffer[liChar] := Chr(Ord(lBuffer[liChar]) + 128)
    else
      lBuffer[liChar] := Chr(Ord(lBuffer[liChar]) - 128);
  Move(PChar(@lBuffer[1])^, Buffer, Result);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  lSS, lTS: TFileStream;
  lDS: TDecompressionStream;
  t: TDateTime;
begin
  t := Now;
  lSS := TFileStream.Create('tst', fmOpenRead);
  try
    lDS := TDecompressionStream.Create(lSS);
    try
      lTS := TFileStream.Create('dec.exe', fmCreate);
      try
        lTS.CopyFrom(lDS, lSS.Size);
      finally
        lTS.Free;
      end;
    finally
      lDS.Free;
    end;
  finally
    lSS.Free;
  end;
  Memo1.Lines.Add(FormatDateTime('ss:zzz', Now -t));
end;
aikimarkCommented:
@deathman5

"Fast Encryption" isn't very specific.  Can you help us better understand your problem?
1. How big are these 200 files? (min, max, avg)
2. Where are the 200 files? (local hard drive, file server)
3a. What kind of files are they?
3b. Can these files be opened by another user at the time you want to encrypt them?
4. What are you willing to trade-off for speed?

More on (4)...
The encryption that JACCO has provided is very simple and the actual 'encryption' statements will only consume a fraction of the total time.  Most of the time will be spent with File I/O, open, close.  If you need to protect your files from crackers, you should consider a more robust encryption scheme.  If simply discouraging prying by end users, this might be sufficient.  Your decision depends on the value of the data in these files.
JaccoCommented:
Do you need any other info deathman?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.