微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

BigInteger 作为中性符号

如何解决BigInteger 作为中性符号

我目前正在研究与密码学相关的算法。更具体地说,在椭圆曲线上添加点。有一个选项,我必须处理一种情况,例如添加一个点,例如 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 举报,一经查实,本站将立刻删除。