elliptic_curve-variant.cc

Go to the documentation of this file.
00001 
00007 // this is the variant part of the elliptic curve implementation
00008 // and it must be compiled separately from the invariant part
00009 
00010 // this is because of:
00011 // invariant part: qsieve, net-client and server do share the same code
00012 // variant part: qsieve, net-client and server do not share the same code
00013 
00014 #if defined(IS_SERVER) || !defined(USE_NETWORK)
00015 
00016 void elliptic_curves::factor_found(mpz_t k) const
00017 {
00018   cout << endl << "factor found in elliptic curve" << endl;
00019   if (mpz_cmp(k,n)==0) // factor = n ?
00020    {
00021      cout << "Factorization is trivial, aborting..." << endl;
00022      return; // trivial factor -> abort
00023    }
00024 
00025 #ifdef IS_CLIENT
00026   ostream& Factorization_to_file = cout;
00027 #endif
00028 
00029   if (mpz_probab_prime_p(k,probab_prime_checks))
00030     {
00031       const unsigned int exponent = mpz_remove(n,n,k);
00032       cout << k << " is factor." << endl;
00033 
00034       if (mpz_sizeinbase(k,10)<28)
00035        {
00036          ostringstream comment;
00037          comment << " [ecm" << phase << "]";
00038          Factorization_to_file << MAL(k,exponent,comment) << flush;
00039        }
00040       else
00041        {
00042          ostringstream comment;
00043          comment << " [ecm" << phase << ",sigma=" << sigma << "]";
00044          Factorization_to_file << MAL(k,exponent,comment) << flush;
00045        }
00046     }
00047   else
00048     {
00049       mpz_t h;
00050       mpz_init(h); const unsigned int exponent = mpz_remove(h,n,k);
00051       cout << k << " is a composite factor." << endl;
00052       if (mpz_probab_prime_p(n,probab_prime_checks))
00053        {
00054          mpz_swap(n,k);
00055          cout << k << " is factor. (factorswap)" << endl;
00056          ostringstream comment;
00057          comment << " [ecm" << phase << "/factorswap,sigma=" << sigma << "]";
00058          Factorization_to_file << MAL(k,comment) << flush;
00059        }
00060       else
00061        {
00062          mpz_set(n,h);
00063          if (mpz_sizeinbase(k,10)<28)
00064           {
00065             ostringstream comment;
00066             comment << " [ecm" << phase << "] [composite]";
00067             Factorization_to_file << MAL(k,exponent,comment) << flush;
00068           }
00069          else
00070           {
00071             ostringstream comment;
00072             comment << " [ecm" << phase << ",sigma=" << sigma << "] [composite]";
00073             Factorization_to_file << MAL(k,exponent,comment) << flush;
00074           }
00075        }
00076       mpz_clear(h);
00077     }
00078 }
00079 
00080 #else
00081 // net-client-mode -> transmit factor to server
00082 
00083 void elliptic_curves::factor_found(mpz_t k) const
00084 {
00085   cout << endl << "factor found in elliptic curve, phase " << phase << endl;
00086   if (mpz_cmp(k,n)==0) // factor = n ?
00087    {
00088      cout << "Factorization is trivial, aborting..." << endl;
00089      return; // trivial factor -> abort
00090    }
00091   if (mpz_probab_prime_p(k,probab_prime_checks))
00092     {
00093       cout << k << " is factor." << endl;
00094     }
00095   else
00096     {
00097       cout << k << " is composite factor." << endl;
00098     }
00099   mpz_remove(n,n,k);
00100 
00101   unix_io_stream communication_stream(communication_name, server_port);
00102   communication_stream << "Faktor(ECM)! ";
00103   communication_stream << sigma << " " << k << " " << "ecm" << phase << endl;
00104 
00105   cout << "factor sent to server." << endl;
00106 }
00107 
00108 #endif

Generated on Wed Nov 7 23:29:25 2007 for Qsieve by  doxygen 1.5.4