proj home

Files   Classes   Functions   Hierarchy  

primegen.cpp

Go to the documentation of this file.
00001 
00002 #include <primegen.h>
00003 
00004 
00005 
00006 
00007 void largePrimeGenerator::ensurenbits( ZZ & n, uintc nbits ) const
00008 {
00009   ZZ n2;
00010   ZZ x;
00011   conv(x,"2"); 
00012   power(n2,x,nbits);
00013   if (n<n2)
00014     n += n2;
00015  
00016   if ((n%2)==0)
00017     ++n;
00018 }
00019 
00020 void largePrimeGenerator::findprime_randomly
00021 ( 
00022   ZZ & n, 
00023   uintc nbits 
00024 ) const
00025 {
00026   for ( ; ; )
00027   {
00028     RandomBits(n,nbits);
00029     ensurenbits(n,nbits);
00030     if (isprime(n))
00031       return;
00032   }
00033 }
00034 
00035 
00036 void largePrimeGenerator::findprime_sequentially
00037 ( 
00038   ZZ & n, 
00039   uintc nbits 
00040 ) const
00041 {
00042   RandomBits(n,nbits);
00043   ensurenbits(n,nbits);
00044 
00045   for ( ; ; )
00046   {
00047     if (isprime(n))
00048       return;
00049 
00050     n += 2;
00051   }
00052 }
00053 
00054 bool const largePrimeGenerator::isprime( ZZ const & n ) const
00055 {
00056   for (uint i=0; i<vmax; ++i)
00057     if ((n%v[i])==0)
00058       return false;
00059 
00060   return ProbPrime(n,15);
00061 }
00062 
00063 
00064 largePrimeGenerator::largePrimeGenerator()
00065   : v(0), vmax(1000)
00066 {
00067   PrimeSeq s;
00068 
00069   v = new long int [vmax];
00070 
00071   for (uint i=0; i<vmax; ++i)
00072     v[i] = s.next();
00073 }
00074 
00075 largePrimeGenerator::~largePrimeGenerator()
00076 {
00077   delete[] v;
00078   v=0;
00079 }
00080 
00081 
00082 

Generated on Fri Mar 4 00:49:31 2011 for Chelton Evans Source by  doxygen 1.5.8