Esempio n. 1
0
void SetCoeff(GF2X& x, long i, long val)
{
   if (i < 0) {
      LogicError("SetCoeff: negative index");
      return; // NOTE: helps the compiler optimize
   }

   val = val & 1;

   if (val) {
      SetCoeff(x, i);
      return;
   }

   // we want to clear position i

   long n;

   n = x.xrep.length();
   long wi = i/NTL_BITS_PER_LONG;

   if (wi >= n) 
      return;

   long bi = i - wi*NTL_BITS_PER_LONG;

   x.xrep[wi] &= ~(1UL << bi);
   if (wi == n-1 && !x.xrep[wi]) x.normalize();
}
Esempio n. 2
0
void SetCoeff(GF2X& x, long i, long val)
{
   if (i < 0) {
      Error("SetCoeff: negative index");
      return;
   }

   val = val & 1;

   if (val) {
      SetCoeff(x, i);
      return;
   }

   // we want to clear position i

   long n;

   n = x.xrep.length();
   long wi = i/newNTL_BITS_PER_LONG;

   if (wi >= n) 
      return;

   long bi = i - wi*newNTL_BITS_PER_LONG;

   x.xrep[wi] &= ~(1UL << bi);
   if (wi == n-1) x.normalize();
}
Esempio n. 3
0
void GF2E_WO_MAT_WO_S() {
    long double time = 0.0;
    long whileLoopCnt(0);
    ifstream fin("in2.txt");
    if (!fin) {
        cout << "\n ERROR in Main reading File in.txt...\n";
        exit(1);
    }
    ofstream cheon("exp2/cheon_time_test2_GF2E_WO_MAT_WO_S.txt");
    ofstream teske("exp2/teske_time_test2_GF2E_WO_MAT_WO_S.txt");

    while (!fin.eof()) {
        long r, l, t;
        ZZ p, n, orderOfG;
        GF2X irrdPoly;

        fin >> p >> n >> r >> orderOfG >> l >>t;

        ZZ_p::init(p);

        ZZ_pX id2;
        BuildIrred(id2, conv<long>(n));
        stringstream out;
        out << id2;
        fin >>irrdPoly;
        irrdPoly.zero();
        out>>irrdPoly;
        GF2E::init(irrdPoly);
        GF2E g, h;
        fin >> g >> h;

        cout << "\n p :: " << p << "\t n :: " << n << "\t r :: " << r << "\t orderOfG :: " << orderOfG
                << "\t l :: " << l << "\t t ::" << t << "\t";
        cout << "\n g :: " << g << "\t h :: " << h << "\t irrdPoly :: " << irrdPoly << endl;

        long double cheonTime = 0;
        long double teskeTime = 0;
        discreteLogGF2E *DLP;
        DLP = new discreteLogGF2E(p, n, r, l, g, h, irrdPoly, t, orderOfG);

        for (int i = 0; i < numberOfIterations; ++i) {
            DLP->cheonDL3();
            cheonTime += DLP->getTimeByCheon();
        }

        cheonTime = cheonTime / numberOfIterations;
        if (whileLoopCnt == 0) {
            cheon << "Number of Iterations :: " << numberOfIterations << endl;
            cheon << "Number of Iterations of Walk :: " << DLP->getNumberOfIterations() << endl;
            cheon << "\nr l  t p^n \tTime Cheon \tTable Generation Time \t Gamma Time \tInner Prod Time \tTable Look-Up Time \tMiscellaneous Time \t Actual Multiplication" << endl;
        }
        //        cheon << std::setprecision(5);

        cheon << std::fixed;
        cheon << r << " " << l << " " << trunc(log2(r)) << " 2^" << n << "\t" << cheonTime << " Sec\t   " << DLP->getTableGenerationTime() << " Sec\t\t "
                << DLP->cheon_gammaTime / numberOfIterations << " Sec\t " << DLP->innerProductTime / numberOfIterations
                << " Sec\t\t " << DLP->tableLookUpTime / numberOfIterations << " Sec\t\t"
                << DLP->cheon_miscellaneousTime / numberOfIterations << " Sec\t " << DLP->cheon_actualMultiplicationTime / numberOfIterations << endl;

        cout << "\n Cheon Number Of Iterations :: " << numberOfIterations << " Done...\n";

        for (int i = 0; i < numberOfIterations; ++i) {
            DLP->teske2();
            teskeTime += DLP->getTimeByTeske();
        }
        teskeTime = teskeTime / numberOfIterations;

        if (whileLoopCnt == 0) {
            teske << "Number of Iterations :: " << numberOfIterations << endl;
            teske << "Number of Iterations of Walk :: " << DLP->getNumberOfIterations() << endl;
            teske << "\nr \tp^n \tTime Teske \t" << endl;
        }
        teske << r << "\t2^" << n << "\t" << teskeTime << " Sec" << endl;
        cout << "\n Teske Number Of Iterations :: " << numberOfIterations << " Done...\n";
        cout << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
        DLP->~discreteLogGF2E();

        ++whileLoopCnt;
        if (whileLoopCnt >= numberOfIput) {
            fin.close();
            cheon.close();
            teske.close();
            break;
        }
    }//end::WHILE LOOP
    cheon.close();
    teske.close();
    fin.close();
}