(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
program FileEncrypt;

{$APPTYPE CONSOLE}

uses
  Windows,SysUtils;

const
  N = 1000000;

var
  i,nobyt,actual,t : integer;
  key : string;
  infile,outfile : file;
  buffer : array [1..N] of char;

begin
  key := 'hemmelig';
  t := GetTickCount;
  assign(infile,'C:\z.1');
  reset(infile,1);
  assign(outfile,'C:\z.2');
  rewrite(outfile,1);
  nobyt := 0;
  while not eof(infile) do begin
     blockread(infile,buffer,N,actual);
     for i := 1 to actual do begin
        buffer[i] := chr(ord(buffer[i]) xor ord(key[((nobyt+i) mod length(key))+1]));
     end;
     nobyt := nobyt + actual;
     blockwrite(outfile,buffer,actual);
  end;
  close(infile);
  close(outfile);
  writeln((GetTickCount-t),' milliseconds');
end.
