biginteger作为中性符号

gev0vcfq  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(164)

我目前正在研究一种与密码学相关的算法。更具体地说,在椭圆曲线上加点。有一个选项,我必须处理一种情况,例如添加一个点,例如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 + ")");
        }
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题