Пример #1
0
void point_test(Pixel *PixelBuffer) {

    Points points = {
        { 1 , 5  },
        { 28, 90 },
        { 48, 49 },
        { 93, 26 },
    };

    Points sorted = points;
    Raster raster;
    Point p;

    std::sort(sorted.begin(), sorted.end(), point_sortable);

    point_print_vec(&points);
    point_print_vec(&sorted);

    Points *p_max_min = raster.points_max_min(&points);
    point_print_vec(p_max_min);

    std::cout << "Adding ";
    point_print(sorted[0]);
    std::cout << " to ";
    point_print(sorted[1]);
    std::cout << "\n";
    point_print(sorted[0]+sorted[1]);

    delete(p_max_min);
}
Пример #2
0
int main(void)
{
   EC_PAIRING p;
   EC_POINT a, b, c;
   Element d;

   pairing_init(p, "ECBN254");

   point_init(a, p->g1);
   point_init(b, p->g2);
   point_init(c, p->g1);

   element_init(d, p->g3);

   point_set_str(a,
      "["
         "0000000000000000000000000000000000000000000000000000000000000001,"
         "0D45589B158FAAF6AB0E4AD38D998E9982E7FF63964EE1460342A592677CCCB0"
      "]"
   );

   point_set_str(b,
      "["
         "19850140BC38957238BDEB56EC7B97FE30A6A65D15C4BA07CEF54DB5026C7210 "
         "1DEB7F4B6C1AEFAEBD0EB750B841BD8ABF916EB750FDF7291F99DFD290C28CE0,"
         "14C164D6D18CBC7F64559076E00789C75FF001D1BE0968D210C19FB0D3AD649A "
         "059A2ABA101B7A3C1FA3CAF4DF6B38F2CB4976287488E33F526FA7E8C5441B4B"
      "]"
   );

   pairing_map(d, a, b, p);

   point_print("a", a);
   point_print("b", b);

   element_print("d", d);

   char msg[] = "abc";

   point_map_to_point(c, msg, sizeof(msg), 80);

   point_print("c", c);

   point_clear(a);
   point_clear(b);
   point_clear(c);

   element_clear(d);
   pairing_clear(p);

   return 0;
}
Пример #3
0
/*
 * Step through the next line of gcode in the open file.
 */
int gvm_step(struct gvm *m)
{
	struct command cmd;
	struct point values;
	enum axismask mask;

	if (!m->gcode) {
		bail("no gcode file has been opened");
		return -1;
	}

	/* record for delta queries */
	m->previous = m->position;
	m->prevoffset = m->offset;

	if (gvm_read(m, &cmd, &values, &mask) == 0)
		gvm_apply(m, &cmd, &values, &mask);

	if (m->verbose) {
		fprintf(stderr, "gvm [resu]: ");
		point_print(stderr, &(m->position));
	}

	if (feof(m->gcode) != 0)
		return -1;

	m->counter++;

	return 0;
}
Пример #4
0
int generate_key(ptr_curve_t E, ptr_point_t G, ptr_point_t Q, bases_t d_bases)
{
	mpz_t n;
	mpz_init(n);
	mpz_ui_pow_ui(n,2,M);

	if(DEBUG)gmp_printf("%Zd\n",n);

	gmp_randstate_t rand_stat;
	gmp_randinit_mt(rand_stat);
	gmp_randseed_ui(rand_stat,time(NULL));

	mpz_t d;
	mpz_init(d);
	mpz_urandomb(d,rand_stat,M);

	if(DEBUG)gmp_printf("%Zd\n",d);


	bases_init(d_bases);
	int_to_bases(d,d_bases);

	point_init(Q);

	multiple_point_CE(E,G,d_bases,Q);
	if(DEBUG)
	{
		bases_print(d_bases);
		printf("\n");
		point_print(Q,"Q");
	}
	char buffer [1024];
	FILE *pub, *priv;
	pub = fopen("./pub.key","w+");
	if(pub != NULL){
		memset(buffer, '\0', sizeof(buffer));
		bases_to_string(Q->_x,buffer);
		fputs(buffer,pub);
		fputs(";",pub);
		memset(buffer, '\0', sizeof(buffer));
		bases_to_string(Q->_y,buffer);
		fputs(buffer,pub);
		fclose(pub);
	}
	else
		return ERROR;

	priv = fopen("./priv.key","w+");
	if(priv != NULL){
		memset(buffer, '\0', sizeof(buffer));
		bases_to_string(d_bases,buffer);
		fputs(buffer,priv);
		fclose(priv);
	}
	else
		return ERROR;

	return NERROR;
}//generate_key()
Пример #5
0
void face_print(struct face *face) {
	char *prefx = "";
	printf("{size:%d,[", face->size);
	for (int i = 0; i < face->size; i++) {
		printf("%s", prefx);
		point_print(face->points + i);
		prefx = ",";
	}
	printf("]}");
}
Пример #6
0
/* Output a list to the console */
void point_list_print(struct point_list *l)
{
    int i;
    
    assert(l != NULL);
    
    for (i = 0; i < l->length; i++) {
        point_print(&(l->plist[i]));
    }
}
Пример #7
0
/* Output a list of points from l ordered nearest to farthest from point p */
void point_list_print_all_near_to_far(struct point_list *l, struct point *p)
{
	assert(l != NULL);
	assert(p != NULL);
	
	struct point_list list;
	
	copy_point_list(l, &list);
    
    while(list.length > 0) {
    	int index = point_list_closest(&list, p);
    	point_print(point_list_getindex(&list, index));
    	point_list_remove_index(&list, index);
    }
}
Пример #8
0
void raster_test(Pixel *PixelBuffer) {
    Raster raster;

    Points *pi1 = new Points;
    pi1->push_back({10, 10});
    pi1->push_back({20, 60});

    Points *pi2 = new Points;
    pi2->push_back({5, 20});
    pi2->push_back({60, 25});

    point_print(raster.find_intersection(pi1, pi2));

    delete pi1;
    delete pi2;
}
Пример #9
0
/*Imprime un elemento y devuelve el número de caractéres escritos*/
int elequeue_print(FILE *f, const EleQueue *pele){
	if(!f || !pele){
		return -1;
	}
	return point_print (f, pele->point);
}
Пример #10
0
void ECDSA_sign_file (char * path, ptr_curve_t E, ptr_point_t G, ptr_point_t Q, bases_t d_bases, mpz_t r, mpz_t s)
{
	printf("\n\tStrat EC-DSA algo\n");
	mpz_t k_inv, r0, r1, r2, n, d, k, z, x1;
	mpz_init(k_inv);
	mpz_init(r0);
	mpz_init(r1);
	mpz_init(r2);
	mpz_init(s);
	mpz_init(k);
	mpz_init(z);
	mpz_init(x1);
	mpz_init(r);

	bases_t k_bases;
	bases_init(k_bases);

	point_t X;
	point_init(&X);

	//sha-256 de m
	char buffer[65];
	char buffer_M[40];
	mpz_init(n);
	mpz_ui_pow_ui(n,2,M);
	mpz_init(d);
	bases_to_int(d_bases,d);

	mpz_t seed;
	mpz_init_set_str(seed,"85e25bfe5c86226cdb12016f7553f9d0e693a268",16);
	gmp_randstate_t rand_stat;
	gmp_randinit_default(rand_stat);
	gmp_randseed(rand_stat,seed);
	//gmp_randseed_ui(rand_stat,time(NULL));
	//k*G=(x1,y1) (un scalaire fois un point)

	int step_3 = 0;
	while(!step_3)
	{
		mpz_urandomb(k,rand_stat,M);
		if(DEBUG)gmp_printf("%Zd\n",k);
		int_to_bases(k,k_bases);
		multiple_point_CE(E,G,k_bases,&X);

		if(DEBUG)point_print(&X,"X");

		//r=x1 mod n (x1 est transformé en integer)
		bases_to_int(X._x,x1);

		if(DEBUG)gmp_printf("%Zd\n",x1);
		mpz_mod_2exp(r,x1,M);
		if(mpz_cmp_ui(r,0)<=0)
		{
			printf("\tRestart EC-DSA algo because r = 0\n");
			continue;
		}

		if(DEBUG)gmp_printf("r = x1 mod n, r = %Zd\n", r);
		//z = Hex_to_int(sha-256(M))
		sha256_file(path,buffer);
		strncpy(buffer_M,buffer,40);
		mpz_init_set_str(z,buffer_M,16);

		//s= k^-1(z+r*d) mod n (multiplication d'integers)
		mpz_invert(k_inv,k,n);
		mpz_mul(r0,r,d);
		mpz_add(r1,z,r0);
		mpz_mul(r2,k_inv,r1);
		mpz_mod_2exp(s,r2,M);
		//if s = 0 go to step_3
		if(mpz_cmp_ui(s,0)>0)
		{
			step_3 = 1;
		}
		else
		{
			printf("\tRestart EC-DSA algo because s = 0\n");
		}
	}
	printf("\t\thash : sha-256(M) = %s\n", buffer);
	gmp_printf("\t\tz = %Zd\n",z);
	gmp_printf("\t\tr = %Zd\n",r);
	gmp_printf("\t\ts = %Zd\n",s);
	printf("\tEnd EC-DSA algo\n");
}//ECDSA_sign_file()
Пример #11
0
int elestack_print(FILE *f, const EleStack *ppoint){
	if(!f || !ppoint){
		return -1;
	}
	return point_print (f, ppoint->point);
}
Пример #12
0
int main(int argc, char* argv[]){
	Image* src;
	Module *scene;
	Module* GRAPHICS;
	View3D view;
	Matrix vtm, gtm;
	DrawState *ds;
	Lighting *light;
	Point center;//center of animation
	Polygon poly;//polygon that holds the animation path points
	int frameNum;//holds the frame number for animation
	char filename[100];//holds the frame name
	Color Red;
	Color Blue;
	Color Green;
	Color Grey;
	Color Lemon;
	Color Black;
	Color White;
	Color Yellow;
	Color DarkAmbiant;
	Color randColor[10];


	//setting colors
	Color_set(&Red, 1.0, 0.2, 0.1 );
	Color_set(&Blue, 0.1, 0.1, 1.0);
	Color_set(&Green, 0.1, 1, 0.1 );
	Color_set(&White, 1, 1, 1 );
	Color_set(&Grey, 0.7, 0.7, 0.7 );
	Color_set(&Lemon, 1.0, 1.0, 0.8);
	Color_set(&Black, 0.05, 0.05, 0.05);
	Color_set(&Yellow, 1, 0.894118, 0.709804);
	Color_set(&DarkAmbiant, 0.3, 0.3, 0.3);

	Color_set(&randColor[0], 0, 1, 1);
	Color_set(&randColor[1], 0.498039, 1, 0);
	Color_set(&randColor[2], 1, 0.54902, 0);
	Color_set(&randColor[3], 1, 0.0784314, 0.576471);
	Color_set(&randColor[4], 1, 0.843137, 0);
	Color_set(&randColor[5], 0.960784, 1, 0.980392);
	Color_set(&randColor[6], 1, 0.647059, 0);
	Color_set(&randColor[7], 1, 0.270588, 0);
	Color_set(&randColor[8], 0, 1, 0.498039);
	Color_set(&randColor[9], 1, 1, 0);



	// setting the view
	point_set3D( &(view.vrp), 35, 60, 30 );
	vector_set( &(view.vpn), -view.vrp.val[0]+35, -view.vrp.val[1], -view.vrp.val[2]);
	vector_set( &(view.vup), 0, 1, 0 );
	view.d = 1;
	view.du = 1.6;
	view.dv = 0.9;
	view.f = 1;
	view.b = 200;
	view.screenx = 1280;
	view.screeny = 720;

	matrix_setView3D( &vtm, &view );
	matrix_identity( &gtm );


	//creating GRAPHICS module
	GRAPHICS = module_create();
	module_alphabet_G(GRAPHICS);

	module_identity(GRAPHICS);
	module_translate(GRAPHICS, 10, 0, 0);
	module_alphabet_R(GRAPHICS);

	module_identity(GRAPHICS);
	module_translate(GRAPHICS, 20, 0, 0);
	module_alphabet_A(GRAPHICS);

	module_identity(GRAPHICS);
	module_translate(GRAPHICS, 30, 0, 0);
	module_alphabet_P(GRAPHICS);

	module_identity(GRAPHICS);
	module_translate(GRAPHICS, 40, 0, 0);
	module_alphabet_H(GRAPHICS);

	module_identity(GRAPHICS);
	module_translate(GRAPHICS, 50, 0, 0);
	module_alphabet_I(GRAPHICS);

	module_identity(GRAPHICS);
	module_translate(GRAPHICS, 56, 0, 0);
	module_alphabet_C(GRAPHICS);

	module_identity(GRAPHICS);
	module_translate(GRAPHICS, 68, 0, 0);
	module_alphabet_S(GRAPHICS);


	// setting the light
	light = lighting_create();
	lighting_add( light, LightAmbient, &Lemon, NULL, NULL, 0, 0);
	lighting_add(light, LightPoint, &White , NULL, &view.vrp, 0, 0);
	lighting_add(light, LightSpot, &White, &view.vpn, &view.vrp, cos(10*M_PI/180), 40);

	//setting drawstate
	ds = drawstate_create();
	point_copy(&(ds->viewer), &(view.vrp) );
	ds->shade = ShadePhong;
	// ds->shade = ShadeDepth;
	drawstate_setBody(ds, Black);
	drawstate_setSurface(ds, Red);
	drawstate_setSurfaceCoeff(ds, 10);

	//Animation
	frameNum =0;

	//path #1
	point_set3D(&center, 40, 0, -10);
  	view_rotate_circle(&poly, &center, 100, 50, 0, 0, 0);
  	polygon_print(&poly, stdout);
  	for(int k=0; k<100; k++){
  		frameNum++;
		point_set3D( &(view.vrp), poly.vertex[k].val[0], poly.vertex[k].val[1], poly.vertex[k].val[2]);
		vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2] );
		matrix_setView3D( &vtm, &view );

		//creating scene module
		scene = module_create();
		module_module(scene, GRAPHICS);

		// image
		src = image_create( view.screeny, view.screenx );
		image_fillrgb(src, 1.0, 1.0, 0.8);

		//Drawing
		module_draw( scene, &vtm, &gtm, ds, light, src );
		sprintf(filename, "../images/frame_%.4d.ppm",frameNum);
		image_write( src, filename);
	}

	//path #2
	point_set3D(&center, 40, 0, -10);
  	view_rotate_circle(&poly, &center, 100, 90, 0, 0 , 0);
  	// polygon_print(&poly, stdout);
  	for(int k=0; k<100; k++){
  		if(frameNum == 119){
  			point_print(&view.vrp, stdout);
  			break;
  		}
  		view_rotate_circle(&poly, &center, 50, 50+k, 0-2*k, 0 , 0);
  		frameNum++;
		point_set3D( &(view.vrp), poly.vertex[k].val[0], poly.vertex[k].val[1], poly.vertex[k].val[2]);
		vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2] );
		matrix_setView3D( &vtm, &view );

		//creating scene module
		scene = module_create();
		module_module(scene, GRAPHICS);

		// image
		src = image_create( view.screeny, view.screenx );
		image_fillrgb(src, 1.0, 1.0, 0.8);

		//Drawing
		module_draw( scene, &vtm, &gtm, ds, light, src );
		sprintf(filename, "../images/frame_%.4d.ppm",frameNum);
		image_write( src, filename);
	}

	//path #3
	for(int k=0; k<120; k++){

  		frameNum++;
  		if(frameNum <= 160){
			point_set3D( &(view.vrp), -3.345+(k), 36.298+(k), 28.391-(k/2.0));
			vector_set( &(view.vpn), -view.vrp.val[0]+k, -view.vrp.val[1], -view.vrp.val[2]);
			matrix_setView3D( &vtm, &view );
		}

		//creating scene module
		scene = module_create();
		module_module(scene, GRAPHICS);

		if(frameNum == 160){
			light = lighting_create();
			lighting_add( light, LightAmbient, &Grey, NULL, NULL, 0, 0);
		}
		// setting the light
		if(frameNum == 165){
			Point plight1;
			point_set3D(&plight1, -5, 10, -10);

			lighting_add(light, LightSpot, &White, &view.vpn, &plight1, cos(10*M_PI/180), 40);
		}
		if(frameNum == 175){
			Point plight2;
			point_set3D(&plight2, 85, 10, -10);

			lighting_add(light, LightSpot, &White, &view.vpn, &plight2, cos(10*M_PI/180), 40);
		}
		if(frameNum == 180){
			lighting_add(light, LightSpot, &White, &view.vpn, &view.vrp, cos(10*M_PI/180), 40);
		}

		if(frameNum >= 183){
			light = lighting_create();
			lighting_add( light, LightAmbient, &Grey, NULL, NULL, 0, 0);

			int output1 = 0 + (rand() % (int)(10 - 0 + 1));
			int output2 = 0 + (rand() % (int)(10 - 0 + 1));
			int output3 = 0 + (rand() % (int)(10 - 0 + 1));

			Point plight1;
			point_set3D(&plight1, -5, 10, -10);
			lighting_add(light, LightSpot, &randColor[output1], &view.vpn, &plight1, cos(10*M_PI/180), 40);

			Point plight2;
			point_set3D(&plight2, 85, 10, -10);
			lighting_add(light, LightSpot, &randColor[output2], &view.vpn, &plight2, cos(10*M_PI/180), 40);

			lighting_add(light, LightSpot, &randColor[output3], &view.vpn, &view.vrp, cos(10*M_PI/180), 40);
		}
		// image
		src = image_create( view.screeny, view.screenx );
		image_fillrgb(src, 1.0, 1.0, 0.8);

		//setting drawstate
		ds = drawstate_create();
		point_copy(&(ds->viewer), &(view.vrp) );
		ds->shade = ShadePhong;
		// ds->shade = ShadeDepth;
		drawstate_setBody(ds, Black);
		drawstate_setSurface(ds, Red);
		drawstate_setSurfaceCoeff(ds, 10);

		//Drawing
		module_draw( scene, &vtm, &gtm, ds, light, src );
		sprintf(filename, "../images/frame_%.4d.ppm",frameNum);
		image_write( src, filename);
	}

	//***Uncomment for making the .gif animation***
	printf("Making the demo.gif file....\n");
	system("convert -delay 10 ../images/frame_*.ppm ../images/demo.gif");
	printf("Cleaning up...\n");
	system("rm -f ../images/frame_*.ppm");
	printf("Finished Successfully :)\n");
	return(0);
}