home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6668 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.4 KB  |  67 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!rpi!utcsri!newsflash.concordia.ca!IRO.UMontreal.CA!CC.UMontreal.CA!pigeons
  3. From: pigeons@JSP.UMontreal.CA (Pigeon Steven)
  4. Subject: Re: Encryption and Random Numbers
  5. Message-ID: <1992Nov18.030335.15774@cc.umontreal.ca>
  6. Sender: news@cc.umontreal.ca (Administration de Cnews)
  7. Organization: Universite de Montreal
  8. References: <1992Nov17.211502.18511@lynx.dac.northeastern.edu>
  9. Date: Wed, 18 Nov 1992 03:03:35 GMT
  10. Lines: 55
  11.  
  12. In article <1992Nov17.211502.18511@lynx.dac.northeastern.edu> cschmidt@lynx.dac.northeastern.edu (Christopher Schmidt) writes:
  13. >Duncan Murdoch's interesting STREAMS package includes some
  14. >clever encryption logic that uses the TP random number
  15. >generator.  It's a nice technique, except that if Borland
  16. >modifies the TP random number generator, then you and your
  17. >customers will be locked out of your encrypted data.
  18. >
  19. >What exactly are the chances Borland will modify the TP
  20. >random number generator?  Do you feel lucky?
  21. >
  22. >Simple solution: Include your own random number generator in
  23. >your program.  Anybody have such in TP?  I notice there is a
  24. >random number generator in C in the SIMTEL directory
  25. ><MSDOS.C>, but I have not looked at it yet.
  26.  
  27. Good solution!... Better yet if you know that a simple random
  28. generator (such as one found in TP, at least, up to version 6.0)
  29. is ... simple to program: 
  30.  
  31.  
  32.  procedure randomize;
  33.   begin
  34.    RandSeed := timer;
  35.   end;
  36.  
  37.  procedure random(m:word):word;
  38.   begin
  39.    RandSeed:=(RandSeed*C+b) mod (2^32); {keep only the first 32 bits of 
  40.                                         result }
  41.    random:=(RandSeed and $0000ffff) mod m;  {keep lower part, and >=0}
  42.   end;
  43.  
  44.  
  45.  
  46. The big deal about this method, is to find a C that will make
  47. your random generator look random. An arbitrarly (sp!) large
  48. relatively prime number C will do, and B can be any odd constant.
  49. C is relatively prime to 2^32, which does not mean that it is
  50. prime, only that it has no factor smaller (or equals) to (2^32-1).
  51.  
  52. (also note that computing (Randseed*C+b) mod (2^32) may cause 
  53. some problems with overflow... Some assembly lang, and it's done!)
  54.  
  55.  
  56. >
  57. >Christopher Schmidt
  58. >Waltham, Massachusetts, USA
  59. >cschmidt@lynx.northeastern.edu
  60.  
  61.  
  62. -- 
  63.  _ ___  __       __ _  | Steven Pigeon
  64. (_  |  (__ \  / (__ |\ | (a.k.a)
  65. __) |  (__  \/  (__ | \| pigeons@JSP.UMONTREAL.CA
  66. ==Computer Science & Operation Research, Universite de Montreal==
  67.