FGIntPrimeGeneration.PAS 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. {License, info, etc
  2. ------------------
  3. This implementation is made by Walied Othman, to contact me
  4. mail to Walied.Othman@Student.KULeuven.ac.be or
  5. Triade@ace.Ulyssis.Student.KULeuven.ac.be,
  6. always mention wether it 's about the FGInt for Delphi or for
  7. FreePascal, or wether it 's about the 6xs, preferably in the subject line.
  8. If you 're going to use these implementations, at least mention my
  9. name or something and notify me so I may even put a link on my page.
  10. This implementation is freeware and according to the coderpunks'
  11. manifesto it should remain so, so don 't use these implementations
  12. in commercial software. Encryption, as a tool to ensure privacy
  13. should be free and accessible for anyone. If you plan to use these
  14. implementations in a commercial application, contact me before
  15. doing so, that way you can license the software to use it in commercial
  16. Software. If any algorithm is patented in your country, you should
  17. acquire a license before using this software. Modified versions of this
  18. software must contain an acknowledgement of the original author (=me).
  19. This implementaion is available at
  20. http://ace.ulyssis.student.kuleuven.ac.be/~triade/
  21. copyright 2000, Walied Othman
  22. This header may not be removed.
  23. }
  24. Unit FGIntPrimeGeneration;
  25. Interface
  26. Uses Windows, SysUtils, Controls, FGInt;
  27. Procedure PrimeSearch(Var GInt : TFGInt);
  28. Implementation
  29. {$H+}
  30. // Does an incremental search for primes starting from GInt,
  31. // when one is found, it is stored in GInt
  32. Procedure PrimeSearch(Var GInt : TFGInt);
  33. Var
  34. temp, two : TFGInt;
  35. ok : Boolean;
  36. Begin
  37. If (GInt.Number[1] Mod 2) = 0 Then GInt.Number[1] := GInt.Number[1] + 1;
  38. Base10StringToFGInt('2', two);
  39. ok := false;
  40. While Not ok Do
  41. Begin
  42. FGIntAdd(GInt, two, temp);
  43. FGIntCopy(temp, GInt);
  44. FGIntPrimeTest(GInt, 4, ok);
  45. End;
  46. FGIntDestroy(two);
  47. End;
  48. End.