home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / w3_prog / stream11.arj / ENCRYPT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-03-27  |  1.4 KB  |  54 lines

  1. program Encrypt;
  2.  
  3. { Program to demonstrate use of TEncryptFilter }
  4.  
  5. uses
  6.   objects,streams;
  7.  
  8. procedure SyntaxExit(s:string);
  9. begin
  10.   writeln;
  11.   writeln(s);
  12.   writeln;
  13.   writeln('Usage:  ENCRYPT Sourcefile Destfile');
  14.   writeln(' will encrypt sourcefile using key $12345678.');
  15.   writeln(' Run ENCRYPT on the encrypted file to decrypt it.');
  16.   halt(99);
  17. end;
  18.  
  19. var
  20.   Source : PBufStream;
  21.   Dest   : PEncryptFilter;
  22.  
  23. begin
  24.   if paramcount <> 2 then
  25.     SyntaxExit('Two parameters required.');
  26.  
  27.   { Open the source file with a buffer size of 2048. }
  28.  
  29.   New(Source, Init( Paramstr(1), stOpenRead, 2048) );
  30.   if (Source = nil) or (Source^.status <> stOk) then
  31.     SyntaxExit('Unable to open file '+ParamStr(1)+' for reading.');
  32.  
  33.   { Open the destination file with a buffer size of 2048, and insert it
  34.     into the encrypting filter. }
  35.  
  36.   New(Dest,   Init($12345678, New(PBufStream,
  37.                                   Init( Paramstr(2), stCreate, 2048))));
  38.   if (Dest = nil) or (Dest^.status <> stOk) then
  39.     SyntaxExit('Unable to create file '+Paramstr(2)+'.');
  40.  
  41.   { Encrypt the source file by copying it to the filter.}
  42.  
  43.   Write('Encrypting ',Paramstr(1),' to ',Paramstr(2),'...');
  44.   Dest^.CopyFrom(Source^, Source^.GetSize);
  45.   if Dest^.status <> stOK then
  46.     SyntaxExit('File error during encryption.');
  47.  
  48.   { Dispose of stream variables to close the files.}
  49.  
  50.   Dispose(Source, done);
  51.   Dispose(Dest, done);
  52.  
  53.   Writeln('Done.');
  54. end.