📄 new text document (2).txt
字号:
void random_field( value)
FIELD2N *value;
{
INDEX i;
SUMLOOP(i)
{
Mother( &random_seed);
value->e[i] = random_seed;
}
value->e[0] &= UPRMASK;
}
void static_field( value)
FIELD2N *value;
{
unsigned long fld2[1][6] = {{0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000011}};
copy(fld2[0], value->e);
}
void static1_field( value)
FIELD2N *value;
{
unsigned long fld2[1][6] = {{0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x0000000D}};
copy(fld2[0], value->e);
}
void static2_field( value)
FIELD2N *value;
{
unsigned long fld2[1][6] = {{0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x000000CA}};
copy(fld2[0], value->e);
}
void rand_curve ( curv)
CURVE *curv;
{
curv->form = 1;
random_field( &curv->a6);
null( &curv->a2);
}
void static_curve ( curv)
CURVE *curv;
{
unsigned long crv2[2][6] = {{0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001},
{0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001}};
curv->form = 1;
copy(crv2[0], &curv->a2);
copy(crv2[1], &curv->a6);
//random_field( &curv->a6);
//null( &curv->a2);
}
void rand_point( point, curve)
POINT *point;
CURVE *curve;
{
FIELD2N rf;
random_field( &rf);
poly_embed( &rf, curve, NUMWORD, rf.e[NUMWORD]&1, point);
}
void static_point(point, curve)
POINT *point;
CURVE *curve;
{
unsigned long pnt2[2][6] = {{0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x000000DF},
{0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x000000E8}};
copy(pnt2[0], &point->x);
copy(pnt2[1], &point->y);
}
int main()
{
FIELD2N private1, private2, send_data, get_data;
CURVE Public_Curve;
POINT Base_Point, Their_public, Hidden_data, Random_point;
INDEX error;
FIELD2N poly_prime = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x000001C3};
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");
static_curve(&Public_Curve);
print_curve("Public curve", &Public_Curve);
static_point(&Base_Point, &Public_Curve);
print_point("Base point", &Base_Point);
printf("\ncreate side 2's private key \n\n");
static1_field(&private2);
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");
static2_field(&send_data);
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);
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 + -