c中素域上椭圆曲线上的点运算

c中素域上椭圆曲线上的点运算,c,cryptography,geometry,C,Cryptography,Geometry,我正试图编写一个程序,在素数域的椭圆曲线上执行点运算,我在代码中使用标准公式进行点加法和加倍,这些运算是由调用的函数执行的,但我得到的是某些点的输出,但不是全部,所以请帮我解决存在的问题在这个代码中 structure point_multiply(int x, int y, int k ) { int xk; int yk,m; xk=x; yk=y; m=1; int xL,yL,s,e; e=findInverse((2*yk),211); if((((3*(xk*xk))*e)% 211

我正试图编写一个程序,在素数域的椭圆曲线上执行点运算,我在代码中使用标准公式进行点加法和加倍,这些运算是由调用的函数执行的,但我得到的是某些点的输出,但不是全部,所以请帮我解决存在的问题在这个代码中

structure point_multiply(int x, int y, int k )
{
int xk;
int yk,m;
xk=x;
yk=y;
m=1;
int xL,yL,s,e;
e=findInverse((2*yk),211);
if((((3*(xk*xk))*e)% 211)>0)
{s = (((3*(xk*xk))*e)% 211);

}
else
    s=(((3*(xk*xk))*e)% 211)+ 211;
if((((s*s)- (2*xk)) % 211)>0)
{xL=(((s*s)- (2*xk)) % 211);
}
        else
        xL=(((s*s)- (2*xk)) % 211) + 211;
        if(((-yk+ s*(xk-xL)) % 211) > 0)
        yL=(-yk+ s*(xk-xL)) % 211;
        else
        yL=(-yk+ s*(xk-xL)) % 211 + 211;
        xk=xL;
        yk=yL;
        m=m+1;

while(k>m)
{
    sn=point_addition(xk,yk,x,y);
    xk=sn.a;
    yk=sn.b;
    m++;


}
s1.a=xk;
s1.b=yk;
return s1;
}

}

int findInverse(int a,int b)
{
int x[3];
int-y[3];
整数商=a/b;
整数余数=a%b;
x[0]=0;
y[0]=1;
x[1]=1;
y[1]=商*-1;
int i=2;
对于(;(b%(a%b))!=0;i++)
{
a=b;
b=余数;
商=a/b;
余数=a%b;
x[i%3]=(商*-1*x[(i-1)%3])+x[(i-2)%3];
y[i%3]=(商*-1*y[(i-1)%3])+y[(i-2)%3];
}
//x[i-1%3]是a的倒数
//y[i-1%3]是b的倒数

if(x[(i-1)%3]你需要更具体一些。输入是什么,输出是什么,预期的输出是什么?你试过调试吗?你能知道错误可能在哪里吗?还有,你说你只得到某些点的输出。你是说你得到了其他点的错误输出还是根本没有输出?如果没有输出,那么pr问题可能在于输入/输出管理?该代码几乎不可读。@Shahbaz。预期的输出是输出窗口中显示的要发送和解密的点应该是相同的。我认为对于程序中某个较大的数字,它超出了允许的范围int@GregS.编辑了帖子并添加了更多细节
structure point_addition(int x1, int y1, int x2, int y2)
{
int s,xL,yL;
if((x1-x2)!=0)
{
    if ( x1 == 0 && y1 == 0 )
    {
        xL = x2;
        yL = y2;
        s7.a=xL;
        s7.b=yL;
        return s7;
    }
    if ( x2 == 0 && y2 == 0 )
    {
        xL = x1;
        yL = y1;
        s7.a=xL;
        s7.b=yL;
        return s7;
    }
    if ( y1 == -y2 )
    {
        xL = yL = 0;
        s7.a=xL;
        s7.b=yL;
        return s7;
    }
    l=findInverse((x1-x2),211);
    if ((((y1-y2)*l) % 211)>=0)
          s=((((y1-y2)*l) % 211));
    else
          s=(((y1-y2)*l) % 211) + 211;
    if ((((s*s)-(x1+x2)) % 211)>0)
          xL= (((s*s)-(x1+x2)) % 211) ;
    else
          xL= (((s*s)-(x1+x2)) % 211) + 211;
    if(((-y1+s*(x1-xL)))>=0)
          yL= ((-y1+s*(x1-xL)) % 211);
    else
          yL= ((-y1+s*(x1-xL)) % 211) + 211;
}
else

{
    xL= 0 ;
    yL= 0;

}

s7.a= xL;
s7.b= yL;

return s7 ;
int findInverse(int a, int b)
{
 int x[3];
 int y[3];
 int quotient  = a / b;
 int remainder = a % b;
 x[0] = 0;
 y[0] = 1;
 x[1] = 1;
 y[1] = quotient * -1;
 int i = 2;
 for (; (b % (a%b)) != 0; i++)
 {
  a = b;
  b = remainder;
  quotient = a / b;
  remainder = a % b;
  x[i % 3] = (quotient * -1 * x[(i - 1) % 3]) + x[(i - 2) % 3];
  y[i % 3] = (quotient * -1 * y[(i - 1) % 3]) + y[(i - 2) % 3];
 }

 //x[i — 1 % 3] is inverse of a
 //y[i — 1 % 3] is inverse of b
 if(x[(i - 1) % 3]<0)
return x[(i - 1) % 3]+211;
 else
 //x[i — 1 % 3] is inverse of a
 //y[i — 1 % 3] is inverse of b
 return x[(i - 1) % 3];
  }
int main()
{
int y,z=0,x=2,i[200],j[200],h=0,g,k;
    while(x<200)
    {
        y=sqrt((x*x*x)-4);
        z=modulo(y,211);
        if(z!=0)
        {
            i[h]=x;
            j[h]=z;
            s[h].a=i[h];
            s[h].b=j[h];
            s[h+1].a=i[h];
            s[h+1].b=(211 - j[h]);
            printf("\nh=%d X= %d Y= %d \nh=%d X= %d Y= %d",h,s[h].a,s[h].b,h+1,s[h+1].a,s[h+1].b);
            h=h+2;
        }
        x++;

    }
    printf("The total no of points we have on our elliptic curve for cryptography is %d",h-1);
    x=5;
    y=11;
    printf("\n %d %d\n",x,y );
    printf("\nEnter A number between 0 and   the private key");
    scanf("%d",&k);
    s2=point_multiply(x,y,k);
   printf("\n The public key is \n %d %d \n  ",s2.a,s2.b );
   printf("Enter a RANDOM number to generate the cipher texts");
scanf("\n%d",&g);
s3= point_multiply(x,y,g);
s4=point_multiply(s2.a,s2.b,g );
label:
printf("\n Enter a number to send");
scanf("%d",&h);
s6=point_addition(s4.a,s4.b,s[h].a,s[h].b);
printf("The points to be sent are X= %d Y=%d",s[h].a,s[h].b);
printf(" \n X= %d Y=%d\n X = %d Y= %d ",s3.a,s3.b,s6.a,s6.b);
//RECIEVER
s8=point_multiply(s3.a,s3.b,k);
s9=point_addition((s8.a) ,-((s8.b)%211),s6.a,s6.b);
printf(" The decrypted points are \n %d %d",s9.a,s9.b);
        printf("\n If you have more no to send press 1 else press 0");
        scanf("\n %d", &x1);
        if(x1==1)
            goto label;
        else
            return 0;