home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / FLXKEY10.ZIP / RANDCODE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  2.7 KB  |  88 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to build two random encryption-code strings, and    *)
  4. (* then save them to disk.                                            *)
  5. (**********************************************************************)
  6.  
  7. program MakeRandomEncryptioncodes;
  8.  
  9. type          (* 20 character string definition.                      *)
  10.   st20 = string[20];
  11.  
  12. var           (* String index variable.                               *)
  13.   Index : byte;
  14.  
  15.               (* 2 encryption-code strings.                           *)
  16.   Ecode1,
  17.   Ecode2 : st20;
  18.  
  19.               (* Temporary file varialble.                            *)
  20.   TempFile : file;
  21.  
  22.               (* Main program execution block.                        *)
  23. BEGIN
  24.               (* Clear the encryption-code strings.                   *)
  25.   fillchar(Ecode1, sizeof(Ecode1), 0);
  26.   fillchar(Ecode2, sizeof(Ecode2), 0);
  27.  
  28.               (* Set the length byte for both encryption-code strings *)
  29.               (* to 20.                                               *)
  30.   Ecode1[0] := #20;
  31.   Ecode2[0] := #20;
  32.  
  33.               (* Ensure that the data will be random.                 *)
  34.   randomize;
  35.  
  36.               (* Assign random data to each of the encryption-code    *)
  37.               (* strings.                                             *)
  38.   for Index := 1 to 20 do
  39.     begin
  40.       Ecode1[Index] := chr(random(256));
  41.       Ecode2[Index] := chr(random(256))
  42.     end;
  43.  
  44.               (* Open first encryption-code string file.              *)
  45.   assign(TempFile, 'ECODE1.DAT');
  46.   {$I-}
  47.   rewrite(TempFile, 1);
  48.   {$I+}
  49.  
  50.               (* Check for errors.                                    *)
  51.   if (ioresult <> 0) then
  52.     begin
  53.       writeln(' Error opening "ECODE1.DAT" file.');
  54.       halt
  55.     end;
  56.  
  57.               (* Write first ecryption-code string to disk.           *)
  58.   writeln;
  59.   writeln(' Writing first encryption-code to disk.');
  60.   blockwrite(TempFile, Ecode1, succ(length(Ecode1)));
  61.  
  62.               (* Close first encryption-code string file.             *)
  63.   close(TempFile);
  64.  
  65.               (* Open second encryption-code string file.             *)
  66.   assign(TempFile, 'ECODE2.DAT');
  67.   {$I-}
  68.   rewrite(TempFile, 1);
  69.   {$I+}
  70.  
  71.               (* Check for errors.                                    *)
  72.   if (ioresult <> 0) then
  73.     begin
  74.       writeln(' Error opening "ECODE2.DAT" file.');
  75.       halt
  76.     end;
  77.  
  78.               (* Write second ecryption-code string to disk.          *)
  79.   writeln;
  80.   writeln(' Writing second encryption-code to disk.');
  81.   blockwrite(TempFile, Ecode2, succ(length(Ecode2)));
  82.  
  83.               (* Close second encryption-code string file.            *)
  84.   close(TempFile)
  85. END.
  86.  
  87.  
  88.