问题描述
我目前正在研究与密码学相关的算法。更具体地说,在椭圆曲线上添加点。有一个选项,我必须处理一种情况,例如添加一个点,例如 P(x,y) = (1,4) 和一些中性点的符号,例如Q=(e,e)。这种“加法”的结果应该是点(1,4)。它 (e) 不能是零值,因为那么点将是 Q(qx,qy)=(0,0) 并且另一个函数将被激活,因此结果也会不同。您可以为 BigInteger 分配一个符号吗? 我需要类似的东西
if(qx == e){
BigInteger r1 = x1;
BigInteger r2 = x2;
}
这里是完整的功能:
static void addPoints(BigInteger x1,BigInteger y1,BigInteger x2,BigInteger y2,BigInteger a,BigInteger b,BigInteger p) throws Exception {
BigInteger lambda = null;
BigInteger x3 = null;
BigInteger y3 = null;
if (x1.compareTo(x2) == 0 && y1.compareTo(y2) == 0) { //same points
lambda = (((new BigInteger("3").multiply(x1.pow(2))).add(a))
.multiply(Modul1.getReverseNumber(
(new BigInteger("2").multiply(y1)),p)))
.mod(p);
x3 = ((lambda.pow(2)).subtract(new BigInteger("2").multiply(x1))).mod(p);
y3 = ((lambda.multiply(x1.subtract(x3))).subtract(y1)).mod(p);
} else if (x1.compareTo(x2) != 0) { //points are diffrent
lambda = ((y2.subtract(y1)).multiply(
Modul1.getReverseNumber(x2.subtract(x1),p)
)).mod(p);
x3 = (((lambda.pow(2)).subtract(x1)).subtract(x2)).mod(p);
y3 = ((lambda.multiply(x1.subtract(x3))).subtract(y1)).mod(p);
} else if (x1.compareTo(x2) == 0 && y1.compareTo(p.subtract(y2)) == 0) { //y2 is negate
System.out.println(O);
} else { //Point add Neutral Point
System.out.println("Punkt P + neutral : (" + x1 + "," + y1 + ")");
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)