Exemplo n.º 1
0
void test_case()
{
    gen_number();
    putchar(' ');
    gen_number();
    puts("");
}
Exemplo n.º 2
0
void inserter(void) {

    struct buffer_item item;

    printf("Inserting\n");
    //Waits until there are no deleters
    while(deleters != 0)
    {
        sleep(5);
    }
    //Waits until it's the only inserter
    while(inserters != 0)
    {
        sleep(5);
    }
    //Makes itself known to the world
    inserters = 1;
    //Generates number for new link
    item.number = gen_number(100, 1);
    //Ensures that we are at the end of the list
    while(buff.cur->next != NULL)
    {
        buff.cur = buff.cur->next;
    }
    //Add the new node to the list
    buff.cur->next = &item;
    buff.cur = buff.cur->next;
    buff.cur->next = NULL;
    buff.items++;
    printf("Added %d to end\n", item.number);
    //No more inserters
    inserters = 0;
}
Exemplo n.º 3
0
NUMBER generate_prime(int len, int prob) 
{
	NUMBER a_three,a_four;
	NUMBER prim ;
	int i ;
	
	a_add( &a_one, &a_two, &a_three );
	a_add( &a_two, &a_two, &a_four );

	init_rnd();
	
	do {
		gen_number( len, &prim );
	} while ( !prim.n_len );
	
	a_mult( &prim, &a_two, &prim );
	a_mult( &prim, &a_three, &prim );
	a_add( &prim, &a_one, &prim );
	
	for (i=1 ;; i++) {
		if (p_prim( &prim, prob ))
			break;
		if (i % 2)
			a_add( &prim, &a_four, &prim );
		else
			a_add( &prim, &a_two, &prim );
	}
	
	//num_fput( &prim, stdout );
	return prim ;
}
Exemplo n.º 4
0
static VALUE rb_cObject_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
  ID sym_to_json = rb_intern("to_json");
  if ( rb_hash_aref(state, rb_str_new2("processing_key")) != Qtrue && rb_respond_to(self, sym_to_json) ) {
    VALUE json_opts = rb_hash_aref(state, rb_str_new2("json_opts"));
    VALUE str = rb_funcall(self, sym_to_json, 1, json_opts);

    gen_number(rb_yajl_gen, str);
  } else {
    gen_string_to_s(rb_yajl_gen, self);
  }

  return Qnil;
}
Exemplo n.º 5
0
int generate_key(NUMBER p1, NUMBER p2, NUMBER_SET *g_public_key, NUMBER_SET *g_secret_key)
{
	NUMBER n,d,e,phi,*max_p;
	int len;
	
	if ( !a_cmp( &p1, &p2 ) ) {
		//fprintf(stderr,"the prime numbers must not be identical!\n");
		//exit(1);
		return -1 ;
	}
	
	if (a_cmp( &p1, &p2 ) > 0)
		max_p = &p1;
	else
		max_p = &p2;

	a_mult( &p1, &p2, &n );

	a_sub( &p1, &a_one, &phi );
	a_sub( &p2, &a_one, &e );
	a_mult( &phi, &e, &phi );
	
	len = n_bitlen( &phi );
	len = ( len + 3 ) / 4;
	
	a_assign( &p1, &phi );
	a_sub( &p1, &a_one, &p1 );
	init_rnd();
	do {
		do {
			gen_number( len, &d );
		} while (a_cmp( &d, max_p ) <= 0 || a_cmp( &d, &p1 ) >= 0);
				
		a_ggt( &d, &phi, &e );
	} while ( a_cmp( &e, &a_one ) );
	
	inv( &d, &phi, &e );
	
	// public key
	a_assign(&(g_public_key->n_key1), &n) ;
	a_assign(&(g_public_key->n_key2), &e) ;

	// secret key
	a_assign(&(g_secret_key->n_key1), &n) ;
	a_assign(&(g_secret_key->n_key2), &d) ;

	return 0 ;
}
Exemplo n.º 6
0
static VALUE rb_cFixnum_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
  VALUE str = rb_funcall(self, rb_intern("to_s"), 0);
  char *cptr = RSTRING_PTR(str);

  if (memcmp(cptr, "NaN", sizeof("NaN")) == 0 || memcmp(cptr, "Infinity", sizeof("Infinity")) == 0 || memcmp(cptr, "-Infinity", sizeof("-Infinity")) == 0) {
    rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
  }

  if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
    gen_string(rb_yajl_gen, str);
  } else {
    gen_number(rb_yajl_gen, str);
  }

  return Qnil;
}