c语言简单实现elgamal椭圆曲线算法

#include<cstdio>
#include<cmath>
#include<iostream>
#include<time.h>




using namespace std;
struct zuobiao
{
int x;
int y;
};


int  EX_gcd(int a, int b, int &s,int &t)//无问题
{
if (a == 0 && b == 0) {
return -1;
}
if (b == 0) {
s = 1;
t = 0;
return a;
}
int  d = EX_gcd(b, a%b, t,s);
t -= a / b*s;
return d;
}
int  f1(zuobiao P,zuobiao q,int a,int p) //求λ的值  这里的除法a/b=a*b^-1(modp)
{ int  k,c,b,e,t;
if ((P.x==q.x)&&(P.y==q.y)) { //此处只有加法规则的第三步,无(1)(2)
c = ((3 * q.x*q.x + a)%p+p)%p;
b= (2 *P.y);
EX_gcd(b, p, e,t);
while (e < 0) {
e = (e + p)% p;
}
k = (c*e+p)%p;
//cout << k << endl;
}
else {
c = ((q.y - P.y) % p + p ) % p;
b = ((q.x - P.x) % p + p) % p;
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值