Ejemplo n.º 1
0
int main(void)
{   
  
    extern int flag;
    int i, j;
    int arr[HIGHT][WIDTH] = {0};
    int ch;

    initArr(arr);

    initscr();/* Start curses mode */
    cbreak();/* Line buffering disabled, Pass on * everty thing to me */
    keypad(stdscr, TRUE);/* I need that nift                        y F1 */
    noecho();
    start_color();/* Start the color functionality */

    printWin(arr);

    /* Initialize the window parameters */
    mvprintw(0,0,"%s","Press F1 to exit");
    while((ch = getch()) != KEY_F(1))
    {
        switch(ch)
        {
            case KEY_LEFT:
            case 'h':
            leftArrow(arr);
            printWin(arr);
            break;
            case KEY_RIGHT:
            case 'l':
            rightArrow(arr);
            printWin(arr);
            break;
            case KEY_UP:
            case 'k':
            upArrow(arr);
            printWin(arr);
            break;
            case KEY_DOWN:
            case 'j':
            downArrow(arr);
            printWin(arr);
            break;
        }
    }
    endwin();
    return 0;
}   
Ejemplo n.º 2
0
int pollardsRho(mpz_t *n)
{
	mpz_t myN, x_fixed, cycle_size, x, factor, count, tmp;
	long counter = 0;
	int status = FAIL;

	printf("Trying Pollards rho\n");

	mpz_init_set(myN, *n);
	mpz_init_set_ui(x_fixed, POLRHOXFIXED);	mpz_init_set_ui(cycle_size, POLRHOCYCLESIZE);
	mpz_init_set_ui(x, POLRHOX);			mpz_init_set_ui(factor, POLRHOFACTOR);
	mpz_init(tmp);							mpz_init(count);

	while (counter < POLRHOMAX)
	{

		mpz_set_ui(count, 1);
		while (mpz_cmp(count, cycle_size) <= 0 && mpz_cmp_ui(factor, 1) <= 0)
		{
			mpz_mul(x, x, x);				//x = (x*x+1)%number;
			mpz_add_ui(x, x, 1);
			mpz_mod(x, x, myN);
			
			mpz_sub(tmp, x, x_fixed);		//factor = gcd(x - x_fixed, number);
			mpz_gcd(factor, tmp, myN);			

			mpz_add_ui(count, count, 1);
		}

		if (mpz_cmp_ui(factor, 1) > 0)
		{
			printWin(&factor, "Pollards rho");
			status = WIN;
			break;
		}

		mpz_mul_ui(cycle_size, cycle_size, 2);		//cycle_size *= 2;
		mpz_set(x_fixed, x);		

		counter += 1;
	}

	mpz_clear(myN);
	mpz_clear(x_fixed);		mpz_clear(cycle_size);	mpz_clear(x);
	mpz_clear(factor);		mpz_clear(count);		mpz_clear(tmp);

	return status;

}
Ejemplo n.º 3
0
void printBoard()
{
     if(win==true)
     {
                  system("CLS");
                  gameName();
                  draw();
                  printWin();
                  }
     else
     {
          system("CLS");
          gameName();
          draw();
          cout << "Draw" << endl;
     }
 }
Ejemplo n.º 4
0
/* Generate random moduli and check gcd */
int openSSLGenTest(mpz_t *n)
{
	mpz_t myN, genN, tmp;
	long counter = 0;
	int status = FAIL;

	printf("[INFO ] Trying OpenSSL generating\n");

	mpz_init_set(myN, *n);	mpz_init(genN);		mpz_init(tmp);

	BIGNUM *e = NULL;
	RSA *rsa = NULL;

	rsa = RSA_new();
	e = BN_new();
	BN_set_word(e, OPENSSLGENEXPONENT);

	while (counter < OPENSSLGENMAX)
	{

		if (RSA_generate_key_ex(rsa, OPENSSLGENBITS, e, NULL) == 0)
			break;

		mpz_set_str(genN, BN_bn2dec(rsa->n), 10);

		mpz_gcd(tmp, myN, genN);

		if (mpz_cmp_ui(tmp, 1) != 0)
		{
			printWin(&tmp, "OpenSSL gen");
			status = WIN;
			break;
		}

		counter += 1;
	}


	BN_free(e);
	RSA_free(rsa);

	mpz_clear(myN);		mpz_clear(genN);

	return status;
}
Ejemplo n.º 5
0
int shankSquares(mpz_t *n)
{
	mpz_t myN, constA, constB, tmp, tmp2;
	mpz_t Pi, Qi, Plast, Qlast, Qnext, bi;
	long counter = 1;
	int status = FAIL;
	
	printf("[INFO ] Trying shank squares\n");


	mpz_init_set(myN, *n);

	mpz_init(tmp);	mpz_init(tmp2);
	mpz_init(bi);	mpz_init(Qnext);
	mpz_init(Pi);

	mpz_mul_ui(tmp, myN, SHANKQUAREK); // constA = k*N
	mpz_init_set(constA, tmp);

	mpz_sqrt(tmp, constA);	// constB = floor(sqrt(constA))
	mpz_init_set(constB, tmp);

	mpz_init_set(Plast, constB);


	mpz_pow_ui(tmp, Plast, 2);	// Qi = (constA) - (Pi**2)
	mpz_sub(tmp, constA, tmp);
	mpz_init_set(Qi, tmp);

	
	mpz_init_set_ui(Qlast, 1);


	while (counter < SHANKQUAREMAX)
	{

		mpz_add(tmp, constB, Plast);	//bi = floor( (constB) + (Plast) / Qi )
		mpz_fdiv_q(bi, tmp, Qi);

		mpz_mul(tmp, bi, Qi);			//Pi = (bi * Qi) - (Plast)
		mpz_sub(Pi, tmp, Plast);

		mpz_sub(tmp, Plast, Pi);		//Qnext = Qlast + (bi * (Plast - Pi))
		mpz_mul(tmp, tmp, bi);
		mpz_add(Qnext, Qlast, tmp);

		if (mpz_perfect_square_p(Qi) != 0 && counter % 2 == 0)
		{
			break;
		}
		else
		{
			mpz_set(Plast, Pi);
			mpz_set(Qlast, Qi);
			mpz_set(Qi, Qnext);	
		}

		counter += 1;
	}


	mpz_sub(tmp, constB, Plast);	//bi = floor( ( constB - Plast ) / sqrt(Qi) )
	mpz_sqrt(tmp2, Qi);
	mpz_fdiv_q(bi, tmp, tmp2);

	mpz_sqrt(tmp, Qi);				//Plast = (bi * sqrt(Qi)) + Plast
	mpz_mul(tmp, tmp, bi);
	mpz_add(Plast, tmp, Plast);

	mpz_sqrt(Qlast, Qi);

	mpz_pow_ui(tmp2, Plast, 2);		//Qnext = ((constA) - Plast**2) / Qlast
	mpz_sub(tmp, constA, tmp2);
	mpz_div(Qnext, tmp, Qlast);

	mpz_set(Qi, Qnext);

	counter = 0;

	while (counter < SHANKQUAREMAX)
	{
		mpz_add(tmp, constB, Plast);	//bi = floor( ( constB + Plast ) / Qi )
		mpz_fdiv_q(bi, tmp, Qi);

		mpz_mul(tmp, bi, Qi);			//Pi = (bi*Qi) - Plast
		mpz_sub(Pi, tmp, Plast);

		mpz_sub(tmp, Plast, Pi);		//Qnext = Qlast + (bi * (Plast - Pi))
		mpz_mul(tmp, tmp, bi);
		mpz_add(Qnext, Qlast, tmp);

		if (mpz_cmp(Pi, Plast) == 0)
		{
			break;
		}

		mpz_set(Plast, Pi);
		mpz_set(Qlast, Qi);
		mpz_set(Qi, Qnext);

		counter += 1;
	}

	mpz_gcd(tmp, myN, Pi);

	if (mpz_cmp_ui(tmp, 1) != 0 && mpz_cmp(tmp, myN) != 0)
	{
		printWin(&tmp, "Shanks squares");
		status = WIN;
	}

	mpz_clear(myN);		mpz_clear(constA);
	mpz_clear(constB);	mpz_clear(tmp);		mpz_clear(tmp2);
	mpz_clear(Pi);		mpz_clear(Qi);		mpz_clear(Plast);
	mpz_clear(Qlast);	mpz_clear(Qnext);	mpz_clear(bi);

	return status;

}