If you have a PH account, you can customize your PH profile.

View \ENCRYPT.PAS

Supplement Turbovision/object Windows Stream

Submitted By: WEBMASTER
Rating: (Not rated) (Rate It)


{$B-}   { Use fast boolean evaluation. }

program Encrypt;

{ Program to demonstrate use of TEncryptFilter }

uses
  {$ifdef windows}
  wobjects,wincrt,
  {$else}
  objects,
  {$endif}
  streams;

procedure SyntaxExit(s:string);
begin
  writeln;
  writeln(s);
  writeln;
  writeln('Usage:  ENCRYPT Sourcefile Destfile');
  writeln(' will encrypt sourcefile using key $12345678.');
  writeln(' Run ENCRYPT on the encrypted file to decrypt it.');
  halt(99);
end;

var
  Source : PBufStream;
  Dest   : PEncryptFilter;
  filename : string;
begin
  if paramcount <> 2 then
    SyntaxExit('Two parameters required.');

  { Open the source file with a buffer size of 2048. }

  {$ifdef windows}
  Filename := Paramstr(1);
  Filename[length(filename)+1] := #0;
  New(Source, Init( @filename[1], stOpenRead, 2048) );
  {$else}
  New(Source, Init( Paramstr(1), stOpenRead, 2048) );
  {$endif windows}

  if (Source = nil) or (Source^.status <> stOk) then
    SyntaxExit('Unable to open file '+ParamStr(1)+' for reading.');

  { Open the destination file with a buffer size of 2048, and insert it
    into the encrypting filter. }


  {$ifdef windows}
  Filename := Paramstr(2);
  Filename[length(filename)+1] := #0;
  New(Dest,   Init($12345678, New(PBufStream,
                                  Init( @filename[1], stCreate, 2048))));
  {$else}                                             
  New(Dest,   Init($12345678, New(PBufStream,
                                  Init( Paramstr(2), stCreate, 2048))));
  {$endif windows}
  if (Dest = nil) or (Dest^.status <> stOk) then
    SyntaxExit('Unable to create file '+Paramstr(2)+'.');

  { Encrypt the source file by copying it to the filter.}

  Write('Encrypting ',Paramstr(1),' to ',Paramstr(2),'...');
  Dest^.CopyFrom(Source^, Source^.GetSize);
  if Dest^.status <> stOK then
    SyntaxExit('File error during encryption.');

  { Dispose of stream variables to close the files.}

  Dispose(Source, done);
  Dispose(Dest, done);

  Writeln('Done.');
end.

corner
© 1996-2008. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin.
bootstrapLabs Logo A bootstrapLabs project.