Beispiel #1
0
mp_result find_strong_prime(mp_int seed, FILE *fb)
{
  mp_result res;
  mpz_t     t;

  mp_int_init(&t);
  for(;;) {
    if ((res = find_prime(seed, fb)) != MP_TRUE)
      break;
    if ((res = mp_int_copy(seed, &t)) != MP_OK)
      break;

    if ((res = mp_int_mul_pow2(&t, 1, &t)) != MP_OK ||
	(res = mp_int_add_value(&t, 1, &t)) != MP_OK) 
      break;

    if ((res = mp_int_is_prime(&t)) == MP_TRUE) {
      if (fb != NULL)
	fputc('!', fb);

      res = mp_int_copy(&t, seed);
      break;
    }
    else if (res != MP_FALSE) 
      break;

    if (fb != NULL)
      fputc('x', fb);
    if ((res = mp_int_add_value(seed, 2, seed)) != MP_OK)
      break;
  }

  mp_int_clear(&t);
  return res;
}
Beispiel #2
0
/* Find the first apparent prime in ascending order from z */
mp_result mp_int_find_prime(mp_int z)
{
  mp_result  res;

  if(mp_int_is_even(z) && ((res = mp_int_add_value(z, 1, z)) != MP_OK))
    return res;

  while((res = mp_int_is_prime(z)) == MP_FALSE) {
    if((res = mp_int_add_value(z, 2, z)) != MP_OK)
      break;

  }

  return res;
}
Beispiel #3
0
mp_result find_prime(mp_int seed, FILE *fb)
{
  mp_result res;
  int       count = 0;

  if(mp_int_is_even(seed))
    if((res = mp_int_add_value(seed, 1, seed)) != MP_OK)
      return res;
  
  while((res = mp_int_is_prime(seed)) == MP_FALSE) {
    ++count;

    if(fb != NULL && (count % 50) == 0)
      fputc('.', fb);

    if((res = mp_int_add_value(seed, 2, seed)) != MP_OK)
      return res;
  }

  if(res == MP_TRUE && fb != NULL)
    fputc('+', fb);
  
  return res;
}