void main(int argc, char* argv[])
{
	DWORD BegTime;
	double res;

//1-----------------------------------------------------
	BegTime=GetTickCount();
	for(int i=0; i<10000000; i++)
	{
		res=p2_1(i);
	}
	cout << (GetTickCount()-BegTime) << endl;

	BegTime=GetTickCount();
	for(i=0; i<10000000; i++)
	{
		res=p2_2(i);
	}
	cout << (GetTickCount()-BegTime) << endl << endl;

//2-----------------------------------------------------
	BegTime=GetTickCount();
	for(i=0; i<10000000; i++)
	{
		res=p3_1(i);
	}
	cout << (GetTickCount()-BegTime) << endl;

	BegTime=GetTickCount();
	for(i=0; i<10000000; i++)
	{
		res=p3_2(i);
	}
	cout << (GetTickCount()-BegTime) << endl << endl;

//3-----------------------------------------------------
	BegTime=GetTickCount();
	for(i=0; i<10000000; i++)
	{
		res=p4_1(i);
	}
	cout << (GetTickCount()-BegTime) << endl;

	BegTime=GetTickCount();
	for(i=0; i<10000000; i++)
	{
		res=p4_3(i);
	}
	cout << (GetTickCount()-BegTime) << endl;

	BegTime=GetTickCount();
	for(i=0; i<10000000; i++)
	{
		res=p4_2(i);
	}
	cout << (GetTickCount()-BegTime) << endl << endl;

}
Exemple #2
0
void TestSnapStrategy::testSquareDistance()
{
    //tests that it does not work without setting the points
    OrthogonalSnapStrategy toTest;

    QPointF p1;
    QPointF p2;

    qreal resultingRealOne = toTest.squareDistance(p1, p2);
    QVERIFY(resultingRealOne == 0);
    //tests that the returned value is as expected for positive values
    OrthogonalSnapStrategy toTestTwo;

    QPointF p1_2(2,2);
    QPointF p2_2(1,1);

    qreal resultingRealTwo = toTestTwo.squareDistance(p1_2, p2_2);
    QVERIFY(resultingRealTwo == 2);
    //tests that the returned value is as expected for positive and negative values
    OrthogonalSnapStrategy toTestThree;

    QPointF p1_3(2,2);
    QPointF p2_3(-2,-2);

    qreal resultingRealThree = toTestThree.squareDistance(p1_3, p2_3);
    QVERIFY(resultingRealThree == 32);

    //tests that the returned value is 0 when the points are the same
    OrthogonalSnapStrategy toTestFour;

    QPointF p1_4(2,2);
    QPointF p2_4(2,2);

    qreal resultingRealFour = toTestFour.squareDistance(p1_4, p2_4);
    QVERIFY(resultingRealFour == 0);
}
int main( )
{
  int Numbers[] = {10,40,80};      //  The rank of the braid group
  int exp = 100;                   //  The number of experiments to perform for each parameter value
  int Lengths[] = {100,400,800};   //  The length of the base word 
  
  // Generate  instance
  
  for( int n=0 ; n<sizeof(Numbers)/sizeof(int) ; ++n ) {
    for( int l=0 ; l<sizeof(Lengths)/sizeof(int) ; ++l ) {

      int N = Numbers[n];
      int L = Lengths[l];
  
      int success_orig = 0;
      int success_new = 0;
      for( int e=0 ; e<exp ; ++e ) {
	
	cout << "++++++++++++++++++++++++++++++" << endl;
	cout << "e = " << e << endl;
	
	ShftConjKeyInstance SCK = ShftConjKeyInstance::random( N , L , L );
	
	pair< Word , Word > public_key = SCK.getPublicKey( );
	Word p1 = public_key.first;
	Word p2 = public_key.second;
	
	Word delta = getSmallDelta( N+1 );
	NF nf  = NF( N+1 , generatorShift( p1 ) * Word(1) * -delta );
	NF nf2 = NF( N+1 , p2 * -delta );
	
	int time_sec_bound = 60*60  ; // time bound is 60 minutes
	pair< bool , NF > res = nf.areConjugate_uss( nf2 , time_sec_bound );
	if( !res.first ) {
	  cout << "USS failure" << endl;
	  continue;
	}
	NF candidate = res.second;
	
	NF candidate2 = candidate.increaseRank( N+2 );
	NF s2( N+2 , Word(1) );
	NF delta2( N+2 , getSmallDelta( N+2 ) );
	NF p1_2( N+2 , p1 );
	NF p2_2( N+2 , p2 );
	
	candidate2 = centr_attack( N , p1_2 , p2_2 , candidate2 , delta2);
	
	if( ( candidate2 * (-delta2*p1_2*delta2) * s2 * (-delta2*-candidate2*delta2) * -p2_2 ).isTrivial( ) ) {
	  cout << "The key is correct" << endl;

	  // Now check with the original private key
	  NF priv = NF( N+2 , SCK.getPrivateKey( ) );
	  if( priv==candidate2 ) {
	    cout << "The original key obtained" << endl;
	    success_orig++;
	  } else {
	    cout << "The obtained key is new" << endl;
	    success_new++;
	  }
	} else {
	  cout << "The key is not correct" << endl;
	}
	
      }


      int filename_sz = 100;
      char filename[filename_sz];
      ostrstream ostr( filename , filename_sz );
      ostr << "results_N" << N << "_L" << L << ".txt" << ends;
      
      ofstream of( filename );
      of << "N = " << n << endl;
      of << "baseLenth = " << l << endl;
      of << "keyLength = " << l << endl;
      of << "Total experiments: " << exp << endl;
      of << "Successful experiments: " << success_new+success_orig << endl;
      of << "Percentage_orig: " << 100*success_orig/exp << endl;
      of << "Percentage_new: " << 100*success_new/exp << endl;
      // test_inc_rank( );
      
    }
  }
  
  return 0;
}