Пример #1
0
int main(int argc, char *argv[])
{
	mpz_t	a, b, c, p, r;
	
	//init mpz_t
	mpz_init2(a, 576);
	mpz_init2(b, 576);
	mpz_init2(c, 1280);
	mpz_init2(p, 576);
	mpz_init2(r, 576);
        
	//input
	mpz_init_set_str(a, Gx, 16);
	mpz_init_set_str(b, Gy, 16);
	mpz_init_set_str(p, P521, 16);

	//process
	mpz_mul(c, a, b);//c = a *b
	mpz_mod(r, c, p);//r = c mod p

	//output
	mpz_out_str(stdout, 16, c);
	fprintf(stdout, "\r\n");
	mpz_out_str(stdout, 16, r);
	fprintf(stdout, "\r\n");

	//free
	mpz_clear(a);
	mpz_clear(b);
	mpz_clear(c);
	mpz_clear(p);
        
	exit(EXIT_SUCCESS);
}
Пример #2
0
void challenge_39()
{
	mpz_t n, e, d;
	char *p_str = "38b689c351cf329d5efd5676b";
	char *q_str = "54060a750a88d007bd41db2cb";

	rsa_keygen(p_str, q_str, n, e, d);

	size_t pt_len = 32, ct_len = 0;
	unsigned char pt[200] = "yellow submarineyellow submarine";
	unsigned char ct[200] = {0};

	mpz_out_str(stdout, 16, n);
	printf("\n");
	mpz_out_str(stdout, 16, e);
	printf("\n");
	mpz_out_str(stdout, 16, d);
	printf("\n");

	rsa_encrypt(pt, pt_len, ct, ct_len, n, e);

	memset(pt, 0, 32);

	rsa_decrypt(ct, ct_len, pt, pt_len, n, d);

	printf("Plaintext length: %ld\n", pt_len);
	print_binary(pt, pt_len);
}
Пример #3
0
void
checkprimes (unsigned long p1, unsigned long p2, unsigned long p3)
{
  mpz_t          b, f;

  if (p1 - 1 != p2 - 1 + p3 - 1)
    {
      printf ("checkprimes(%lu, %lu, %lu) wrong\n", p1, p2, p3);
      printf (" %lu - 1 != %lu - 1 + %lu - 1 \n", p1, p2, p3);
      abort ();
    }

  mpz_init (b);
  mpz_init (f);

  checkWilson (b, p1); /* b = (p1-1)! */
  checkWilson (f, p2); /* f = (p2-1)! */
  mpz_divexact (b, b, f);
  checkWilson (f, p3); /* f = (p3-1)! */
  mpz_divexact (b, b, f); /* b = (p1-1)!/((p2-1)!(p3-1)!) */
  mpz_bin_uiui (f, p1 - 1, p2 - 1);
  if (mpz_cmp (f, b) != 0)
    {
      printf ("checkprimes(%lu, %lu, %lu) wrong\n", p1, p2, p3);
      printf ("  got  "); mpz_out_str (stdout, 10, b); printf("\n");
      printf ("  want "); mpz_out_str (stdout, 10, f); printf("\n");
      abort ();
    }

  mpz_clear (b);
  mpz_clear (f);

}
Пример #4
0
/* Test all fac(n) cases, with 0 <= n <= limit.  */
void
fac_smallexaustive (unsigned int limit)
{
  mpz_t          f, r;
  unsigned long  n;
  mpz_init_set_si (f, 1);  /* 0! = 1 */
  mpz_init (r);

  for (n = 0; n < limit; n++)
    {
      mpz_fac_ui (r, n);

      if (mpz_cmp (f, r) != 0)
        {
          printf ("mpz_fac_ui(%lu) wrong\n", n);
          printf ("  got  "); mpz_out_str (stdout, 10, r); printf("\n");
          printf ("  want "); mpz_out_str (stdout, 10, f); printf("\n");
          abort ();
        }

      mpz_mul_ui (f, f, n+1);  /* (n+1)! = n! * (n+1) */
    }

  mpz_clear (f);
  mpz_clear (r);
}
Пример #5
0
void
qcn_str (char *num)
{
  mpz_t  z;

  mpz_init_set_str (z, num, 0);

  if (mpz_sgn (z) >= 0)
    {
      mpz_out_str (stdout, 0, z);
      printf (" is not supported (negatives only)\n");
    }
  else if (mpz_fdiv_ui (z, 4) != 0 && mpz_fdiv_ui (z, 4) != 1)
    {
      mpz_out_str (stdout, 0, z);
      printf (" is not a discriminant (must == 0 or 1 mod 4)\n");
    }
  else
    {
      printf ("h(");
      mpz_out_str (stdout, 0, z);
      printf (") approx %.1f\n", qcn_estimate (z));
    }
  mpz_clear (z);
}
Пример #6
0
void
check_one (const char *name, mpz_srcptr x, double y, int cmp, int cmpabs)
{
  int   got;

  got = mpz_cmp_d (x, y);
  if (SGN(got) != cmp)
    {
      unsigned i;
      printf    ("mpz_cmp_d wrong (from %s)\n", name);
      printf    ("  got  %d\n", got);
      printf    ("  want %d\n", cmp);
    fail:
      printf ("  x=");
      mpz_out_str (stdout, 10, x);
      printf    ("\n  y %g\n", y);
      printf ("  x=0x");
      mpz_out_str (stdout, -16, x);
      printf    ("\n  y %g\n", y);
      printf    ("  y");
      for (i = 0; i < sizeof(y); i++)
        printf (" %02X", (unsigned) ((unsigned char *) &y)[i]);
      printf ("\n");
      abort ();
    }

  got = mpz_cmpabs_d (x, y);
  if (SGN(got) != cmpabs)
    {
      printf    ("mpz_cmpabs_d wrong\n");
      printf    ("  got  %d\n", got);
      printf    ("  want %d\n", cmpabs);
      goto fail;
    }
}
Пример #7
0
/*Print signature to standart output stream*/
void signature_print(signature sig)
{
	printf("\nSignature (r,s): \n\t(");
	mpz_out_str(stdout, 10, sig->r);
	printf(",\n\t");
	mpz_out_str(stdout, 10, sig->s);
	printf(")\n");
}
Пример #8
0
void
dump (mpq_t x)
{
  mpz_out_str (stdout, 10, mpq_numref (x));
  printf ("/");
  mpz_out_str (stdout, 10, mpq_denref (x));
  printf ("\n");
}
Пример #9
0
void fill(char file[], mpz_t origSize, mpz_t otherSize)
{
	FILE * filler;
	mpz_t counter;
	mpz_t difference;
	unsigned long int offset = BUFFER_SIZE;	
	unsigned char * empty = NULL;
	unsigned char * temp = calloc(BUFFER_SIZE,sizeof(unsigned char));
	if(!temp)
	{
		puts("Memory error!");
		abort();
	}
	empty = temp;
	memset(empty,'\0',BUFFER_SIZE_IND);
	fpos_t pos;
	mpz_init(counter);
	mpz_init(difference);
//	mpz_sub_ui(origSize,origSize,1);

	mpz_set(counter,otherSize);
	if(!(filler = fopen(file,"r+b")))
	{
		puts("Error!");
	}
	else
	{
		//TODO do mpz_fseek
		fseek(filler,0,SEEK_END);
		printf("=====Filling %s=====\n", file);
		do
		{
			mpz_sub(difference,origSize,counter);
			if(mpz_cmp_ui(difference,BUFFER_SIZE) < 0)
			{
				offset = mpz_get_ui(difference);
			}
			fgetpos(filler,&pos);
			if(fwrite(empty,sizeof(unsigned char), offset, filler) != offset)
			{
				puts("Error filling file!");
				fsetpos(filler,&pos);
			}
			else
			{
				mpz_add_ui(counter,counter,offset);
			}
			mySleep(0);
		}while((mpz_cmp(counter,origSize)<0));
		mpz_out_str(stdout,10,counter);
		printf(" / ");
		mpz_out_str(stdout,10,origSize);
		puts("");
		fclose(filler);
	}
	free(temp);
}
Пример #10
0
Файл: rsa.c Проект: woprandi/RSA
/**
 * \fn  void ecriture_cle(char* nom_fichier, mpz_t nb, mpz_t n)
 * \brief écriture de la clé (nb,n) dans un fichier texte 
 * \param nom_fichier le nom du fichier à écrire
 * \param nb premier nombre de la clé
 * \param n second nombre de la clé
 * */
void ecriture_cle(char* nom_fichier, mpz_t nb, mpz_t n)
{
    FILE* file = fopen(nom_fichier,"w"); // ouverture en écriture avec suppression au préalable
	
    /* écriture de la clé nb n */
    mpz_out_str(file,10,nb);
    fputc('\n',file);
    mpz_out_str(file,10,n);
    
    fclose(file);
    printf("=> Clé écrite dans %s\n", nom_fichier);
}
Пример #11
0
void alder_gmp_test()
{
    mpz_t integ1, integ2;
    mpz_init2 (integ1, 54);
    mpz_init2 (integ2, 54);
    
    mpz_set_ui(integ1, 1);
    mpz_mul_2exp(integ1, integ1, 65);
    mpz_out_str (stdout, 2, integ1);
    printf("\n");
//    mpz_add_ui(integ1,integ1,1);
    
    mpz_out_str (stdout, 10, integ1); printf("\n");
//    mpz_mul_2exp(integ1, integ1, 2);
//    mpz_out_str (stdout, 2, integ1); printf("\n");
    
    uint64_t x2[2];
    x2[0] = 0; x2[1] = 0;
    uint64_t x = 0;
    size_t countp = 0;
    mpz_export(x2, &countp, -1, 8, 0, 0, integ1);
    printf("x[0]: %llu\n", x2[0]);
    printf("x[1]: %llu\n", x2[1]);
    x = UINT64_MAX;
    printf("x: %llu\n", x);
    
    mpz_set_ui(integ1,0);
    
    
//    mpz_mul_2exp(integ1, integ1, );
//    mpz_import(b, 1, 1, sizeof(a), 0, 0, &a);
    // mpz_export
    mpz_out_str (stdout, 2, integ1); printf("\n");
    
    
    mpz_out_str (stdout, 2, integ2);
    printf("\n");
    mpz_swap(integ1, integ2);
    mpz_mul_2exp(integ2, integ1, 2);
    
    mpz_setbit(integ2,0);
    mpz_setbit(integ2,1);
    mpz_out_str (stdout, 2, integ2);
    printf("\n");
    
    mpz_clear (integ1);
    mpz_clear (integ2);
    
}
Пример #12
0
void
test_dsa160(const struct dsa_public_key *pub,
	    const struct dsa_private_key *key,
	    const struct dsa_signature *expected)
{
  struct sha1_ctx sha1;
  struct dsa_signature signature;
  struct knuth_lfib_ctx lfib;
  
  sha1_init(&sha1);
  dsa_signature_init(&signature);
  knuth_lfib_init(&lfib, 1111);
  
  sha1_update(&sha1, LDATA("The magic words are squeamish ossifrage"));
  ASSERT (dsa_sha1_sign(pub, key,
			&lfib, (nettle_random_func *) knuth_lfib_random,
			&sha1, &signature));

  if (verbose)
    {
      fprintf(stderr, "dsa160 signature: ");
      mpz_out_str(stderr, 16, signature.r);
      fprintf(stderr, ", ");
      mpz_out_str(stderr, 16, signature.s);
      fprintf(stderr, "\n");
    }

  if (expected)
    ASSERT (mpz_cmp (signature.r, expected->r) == 0
	    && mpz_cmp (signature.s, expected->s) == 0);
  
  /* Try bad data */
  ASSERT (!DSA_VERIFY(pub, sha1,
		      "The magick words are squeamish ossifrage",
		      &signature));

  /* Try correct data */
  ASSERT (DSA_VERIFY(pub, sha1,
		     "The magic words are squeamish ossifrage",
		     &signature));

  /* Try bad signature */
  mpz_togglebit(signature.r, 17);
  ASSERT (!DSA_VERIFY(pub, sha1,
		      "The magic words are squeamish ossifrage",
		      &signature));

  dsa_signature_clear(&signature);
}
Пример #13
0
int is_residue_test(){
	printf("\n\nTesting the is_residue function\n");
	if(debug)printf("testing is residue for a residue\n");
	unsigned int test_prime = 7;
	unsigned int test_rand = 2384832;
	mpz_t p;
	mpz_init_set_ui(p,test_prime);
	if(debug){
		printf("\ninitial p:");
		mpz_out_str(stdout,10,p);
		printf("\n");
	}
	

	mpz_t p2;
	mpz_init_set_ui(p2,test_rand);
	mpz_mul(p2,p2,p2);
	if(debug){
		printf("\ninitial p2:");
		mpz_out_str(stdout,10,p2);
		printf("\n");
	}
	
	mpz_tdiv_r(p2,p2,p);
	if(debug){
		printf("initial p2^2 (mod p):");
		mpz_out_str(stdout,10,p2);
		printf("\n");
	}
	int result1 = is_residue_modp(p2,p);
	if(debug)printf("is_residue returns %d for the residue\n", result1);

	unsigned int test_prime2 = 19;
	unsigned int test_rand2 = 348909;
	mpz_t q;
	mpz_init_set_ui(q,test_prime2);
	mpz_t q2; 
	mpz_init_set_ui(q2,test_rand2);
	mpz_mul(q2, q2, p);
	mpz_tdiv_r(q2,q2,q);
	int result2 = is_residue_modp(q2,q);
	if(debug)printf("is_residue returns %d for the nonresidue\n", result2);

	int res = !result1||result2;
	if(!res) printf("is_residue PASSED!\n");
	else printf("is_residue FAILED!\n");

	return res; //if 1 is false or 2 is true then we fail
}
Пример #14
0
int
main()
{
	int n = populate_fib();
	printf("%d Fibonacci numbers generated\n", n);
	for (int i = 0; i <= n; i++) {
		printf("%8d:\t", i);
		mpz_out_str(stdout, 10, fib_seq[i]);
		printf("\t");
		mpz_out_str(stdout, 16, fib_seq[i]);
		printf("\n");
	}
	free_internal(fib_seq);
	return EXIT_SUCCESS;
}
Пример #15
0
int
main (int argc, char *argv[])
{
    unsigned long  n;
    unsigned long  limit = 2222;
    mpz_t          f, r;

    tests_start ();

    if (argc > 1 && argv[1][0] == 'x')
        limit = ULONG_MAX;
    else if (argc > 1)
        limit = atoi (argv[1]);

    /* for small limb testing */
    limit = MIN (limit, MP_LIMB_T_MAX);

    mpz_init_set_ui (f, 1);  /* 0# = 1 */
    mpz_init (r);

    for (n = 0; n < limit; n++)
    {
        mpz_primorial_ui (r, n);
        MPZ_CHECK_FORMAT (r);

        if (mpz_cmp (f, r) != 0)
        {
            printf ("mpz_primorial_ui(%lu) wrong\n", n);
            printf ("  got  ");
            mpz_out_str (stdout, 10, r);
            printf("\n");
            printf ("  want ");
            mpz_out_str (stdout, 10, f);
            printf("\n");
            abort ();
        }

        if (isprime (n+1))
            mpz_mul_ui (f, f, n+1);  /* p# = (p-1)# * (p) */
    }

    mpz_clear (f);
    mpz_clear (r);

    tests_end ();

    exit (0);
}
Пример #16
0
int fmpz_fprint(FILE * file, const fmpz_t x)
{
	if (!COEFF_IS_MPZ(*x))
        return fprintf(file, "%ld", *x);
	else 
        return (int) mpz_out_str(file, 10, COEFF_TO_PTR(*x));
}
Пример #17
0
int main (int argc, char *argv[])
{
    mpz_t *a, g;
    int i, n;

    if (argc > 1) {
        n = argc - 1;
        a = malloc(sizeof(mpz_t) * n);
        if (NULL != a) {
            for (i = 1; i <= n; i++)
                mpz_init_set_str(a[i-1], argv[i], 10);

            mpz_init(g);
            gcdn(g, a, n);
            mpz_out_str(NULL, 10, g);
            printf("\n");

            /* No need actually before exit */
            mpz_clear(g);
            for (i = 1; i <= n; i++)
                mpz_clear(a[i-1]);
            free(a);
            return EXIT_SUCCESS;
        }
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}
Пример #18
0
int main(int argc, char **argv) {
    mp_bitcnt_t bit_width = 0;
    int base = kDefaultBase;

    static const struct option long_options[] = {
        { "help", no_argument, NULL, 'h' },
        { "use-random", no_argument, NULL, 'r' },
        { "base", required_argument, NULL, 'b' },
        { "bit-width", required_argument, NULL, 's' },
        { NULL, 0, NULL, 0 }
    };
    for (;;) {
        int opt = getopt_long(argc, argv, "hrb:s:", long_options, NULL);
        if (opt == -1)
            break;

        switch (opt) {
        case 'r':
            gRNGFilename = "/dev/random";
            break;
        case 'b':
            if (simple_strtoi(&base, optarg, 10) < 0 ||
                (base > -2 && base < 2) || base < -36 || base > 62)
                fatal("invalid base: '%s'", optarg);
            break;
        case 's':
            if (simple_strtoul(&bit_width, optarg, 10) < 0 || bit_width == 0)
                fatal("invalid bit width: '%s'", optarg);
            break;
        case 'h':
            print_usage();
            return EXIT_SUCCESS;
        default:
            return EXIT_FAILURE;
        }
    }
    argv += optind;
    argc -= optind;
    if (argc > 2 || (bit_width != 0 && argc > 0))
        fatal("too many arguments");

    mpz_t low, high, result;
    mpz_inits(low, high, result, NULL);
    if (argc == 2) {
        arg_to_mpz(low, argv[0]);
        arg_to_mpz(high, argv[1]);
    } else if (argc == 1) {
        arg_to_mpz(high, argv[0]);
    } else if (bit_width != 0) {
        mpz_setbit(high, bit_width);
    } else {
        mpz_set_ui(high, kDefaultUpperBound);
    }

    get_random_mpz(result, low, high);
    mpz_out_str(stdout, base, result);
    putchar('\n');
    mpz_clears(low, high, result, NULL);
    return EXIT_SUCCESS;
}
Пример #19
0
int _tmain(int argc, _TCHAR* argv[])
{
	mpz_t a, b, c;
	mpz_init(a); mpz_init(b); mpz_init(c);

	mpz_set_str(a, "1024", 10);
	mpz_set_str(b, "768", 10);
	mpz_gcd(c, a, b);

	printf("GCD of "); mpz_out_str(stdout, 10, a);
	printf(" and ");   mpz_out_str(stdout, 10, b);
	printf(" is ");    mpz_out_str(stdout, 10, c);
	putchar('\n');

	return 0;
}
Пример #20
0
/* StrPtrMP_INT : Output an MP_INT in decimal */
void StrPtrMP_INT (FILE * stream, PtrMP_INT a)
{
    if (!a)
        fprintf (stream, "NULL");
    else
        mpz_out_str (stream, 10, a);
}
Пример #21
0
int bbs_test(){
	printf("\n\nstarting bbs test\n");
	bg_prikey prikey = keygen(TEST_KEYSIZE);
	if(debug){
		mpz_out_str(stdout, 16, prikey.n);
		printf("\ndone keygen\n");
	}

	mpz_t r;
	mpz_init(r);
	rand_bigint(r,TEST_KEYSIZE);
	if(debug)printf("got int\n");

	bbs_state* bbs = init_bbs(r, prikey.n);
	bbs_iter(bbs);
	char rand_data [TEST_KEYSIZE];
	bbs_gen(bbs, rand_data, 8*TEST_KEYSIZE, 0);
	bbs_close(bbs);
	
	int i;
	printf("genned bits:0x");
	for(i = 0; i<TEST_KEYSIZE; i++){
		printf("%x ", (int)rand_data[i] & 255);
	}
	printf("\n");
	printf("If the above characters seem random then BBS is probably working\n");
	return 0;
}
Пример #22
0
int main(int argc, char *argv[]) {

    mpz_t base, result;
    int i;
    int sum = 0;

    mpz_init(base);
    mpz_init(result);
    mpz_set_ui(result, 0);
    mpz_set_ui(base, 2);
    
    mpz_pow_ui(result, base, 1000);
    size_t sz = mpz_sizeinbase(result, 10);
    FILE *file = fopen("tmp.txt", "ab+");
    mpz_out_str(file, 10, result);
    fclose(file);
    file = fopen("tmp.txt", "r");

    for (i = 0 ; i  < sz ; i++) {
        sum += fgetc(file) - '0';
    }
    fclose(file);
    remove("tmp.txt");
    printf("%i\n", sum);
    return 0;
}
Пример #23
0
int qsieve_outnum(mpz_t x, FILE *fout)
{
    int t = mpz_out_str(fout, 10, x);
    puts("");
    fflush(stdout);
    return t;
}
Пример #24
0
void print_mp(char* prefix, mpz_t num) {

   printf("%s", prefix);
   mpz_out_str(stdout, 10, num);
   printf("\n");

}
Пример #25
0
int main()
{
    FILE* file;
    file = fopen("result.txt", "w+");

    char digit;
    int sum = 0;
    mpz_t result;

    if (file != NULL)
    {
        mpz_init(result);
        mpz_ui_pow_ui(result, 2, 1000);
        mpz_out_str(file, 10, result);

        fseek(file, 0, SEEK_SET);

        while ((digit=fgetc(file)) != EOF)
        {
            sum += (int)(digit-'0');
        }
    }
    
    std::cout << sum << std::endl;
    mpz_clear(result);
    fclose(file);

    return 0;
}
Пример #26
0
void
table (int numb_bits)
{
  int  i;

  printf ("/* This file generated by gen-fib.c - DO NOT EDIT. */\n");
  printf ("\n");
  printf ("#include \"gmp.h\"\n");
  printf ("#include \"gmp-impl.h\"\n");
  printf ("\n");
  printf ("#if GMP_NUMB_BITS != %d\n", numb_bits);
  printf ("Error, error, this data is for %d bits\n", numb_bits);
  printf ("#endif\n");
  printf ("\n");
  printf ("const mp_limb_t\n");
  printf ("__gmp_fib_table[FIB_TABLE_LIMIT+2] = {\n");

  for (i = 0; i < fnum; i++)
    {
      printf ("  CNST_LIMB (0x");
      mpz_out_str (stdout, 16, f[i]);
      printf ("),  /* %d */\n", i-1);
    }
  printf ("};\n");
}
void
mpn_trace_file (const char *filename, mp_srcptr ptr, mp_size_t size)
{
  FILE   *fp;
  mpz_t  z;

  fp = fopen (filename, "w");
  if (fp == NULL)
    {
      perror ("fopen");
      abort();
    }

  MPN_NORMALIZE (ptr, size);
  PTR(z) = (mp_ptr) ptr;
  SIZ(z) = (int) size;

  mpz_out_str (fp, mp_trace_base, z);
  fprintf (fp, "\n");

  if (ferror (fp) || fclose (fp) != 0)
    {
      printf ("error writing %s\n", filename);
      abort();
    }
}
Пример #28
0
unsigned int choose(unsigned int nInt, unsigned int rInt)
{
    mpz_t n, r, a, b;
    if (    ((nInt - rInt) < 0)
         || ((nInt - rInt) >= TABLE_SIZE)
         || (nInt < 0)
         || (nInt >= TABLE_SIZE)
         || (rInt < 0)
         || (rInt >= TABLE_SIZE))
    {
        printf("bounds fail! n=%d r=%d\n", nInt, rInt);
        exit(1);
    }
    mpz_init(n); mpz_init(r); mpz_init(a); mpz_init(b);
    mpz_set_ui(n, nInt); mpz_set_ui(r, rInt);
    mpz_set(a, factorialTable[nInt - rInt]); // (n - r)!
    mpz_mul(b, factorialTable[rInt], a); // r!(n - r)!
    mpz_tdiv_q(a, factorialTable[nInt], b);
    if (mpz_cmp(a, cutoff) > 0)
    {
        printf("choose(%d,%d)=", nInt, rInt);
        mpz_out_str(stdout, 10, a);
        printf("\n");
        return 1;
    }
    return 0;
}
Пример #29
0
void
dump (const char *name, mpz_t in1, mpz_t in2, mpz_t in3)
{
  printf ("failure in %s (", name);
  0 && mpz_out_str (stdout, -16, in1);
  if (in2 != NULL)
    {
      printf (" ");
      0 && mpz_out_str (stdout, -16, in2);
    }
  if (in3 != NULL)
    {
      printf (" ");
      0 && mpz_out_str (stdout, -16, in3);
    }
  printf (")\n");
}
Пример #30
0
/**
 * generator_print() - print final seed
 * @gen:        generator to query
 * @f:          file to print to
 * @base:       base to print number in
 *
 * This call prints the final seed after a full sequence was parsed via
 * generator_feed(). It prints "<invalid>" if the sequence failed or is not
 * finished, yet.
 */
void generator_print(Generator *gen, FILE *f, int base) {
        GeneratorState *state = gen->tip;

        if (state && state->rule == GENERATOR_PARSER_DONE)
                mpz_out_str(f, base, state->seed);
        else
                fprintf(f, "<invalid>");
}