⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new text document (3).txt

📁 Elliptic Curve Cryptography full working C code for encryption and decryprion.
💻 TXT
字号:
void create_field(value, type, select)
FIELD2N *value;
{
	if(type == 1)
		random_field(value);
	else if(type == 2)
		static_field(value, select);
}

void create_curve(curv, type)
CURVE *curv;
int type;
{
	if(type == 1)
		rand_curve(curv);
	else if(type == 2)
		static_curve(curv);
}

void create_point( point, curve, type)
POINT	*point;
CURVE	*curve;
int type;
{
      if(type == 1)
		rand_point( point, curve);
	else if(type == 2)
		static_point(point, curve);
}






int main()
{

	
     FIELD2N private1, private2, send_data, get_data;
     
     CURVE Public_Curve;

     POINT Base_Point, Their_public, Hidden_data, Random_point;

     INDEX error;

	 int choice = 0, type = 0;
	 
	// FIELD2N  poly_prime = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x000001C3};
	 
	 while(1){

		 printf("ENTER YOUR CHOICE (1: Random, 2:Static)\n");
		 scanf("%d",&choice);

		 switch(choice){
			 case 1:
				 printf("RANDOM\n");
				 type = 1;
				 break;
			 case 2:
				 printf("STATIC\n");
				 type = 2;
				 break;
			 case 3:
				 return 0;
			 default:
				 break;
		 }


		 if (!irreducible(&poly_prime)) return(0);  
			print_field("poly_prime = ", &poly_prime);
			
			
		if (error = init_poly_math())
		{
			printf("Can't initialize S matrix, row = %d\n", error);
			return(-1);
		}
		
		print_curve("Curve = ", &ncrv);

		random_seed = 0xDEADBEEF;

		printf("create Base curve and point\n\n");

		
		create_curve(&Public_Curve, type);
		
        print_curve("Public curve", &Public_Curve);
	 
		 
        create_point( &Base_Point, &Public_Curve, type);
        
		print_point("Base point", &Base_Point);

		printf("\ncreate side 2's private key \n\n");
			 
		
		create_field(&private2, type, 2);
		
        print_field("Side 2 secret: ", &private2);
		     
		print_point("Base point", &Base_Point);

		printf("\nGenerate side 2's public key\n\n");
		     
		poly_elptic_mul( &private2, &Base_Point, &Their_public, &Public_Curve);

		print_point("Side 2 public key", &Their_public);

		     

		printf("\nCreate message data\n\n");

		
       
        create_field(&send_data, type, 3);
		     

		printf("\nHide data on curve and send from side 1 to side 2\n\n");

		send_elgamal( &Base_Point, &Public_Curve, &Their_public, &send_data, &Hidden_data, &Random_point, type);

		print_point("Hidden data", &Hidden_data);

		print_point("Random point", &Random_point);

		printf("\nRecover transmitted message\n\n");

		receive_elgamal( &Base_Point, &Public_Curve, &private2, &Hidden_data, &Random_point, &get_data);

		print_field("sent data   ", &send_data);

		print_field("received data", &get_data); 
		getch();   
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -