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

使用 Point 和 BigInteger

如何解决使用 Point 和 BigInteger

如何在 Java 中将 Point 与 BigInteger 一起使用?下面是我正在尝试做的一个例子。新的 Point 生成器抛出一个错误,它无法将 BigInterger 转换为 Int,我可以通过执行 .intValue() 来修复该错误,但随后在 publicKey 行上,它会在使用 .multiply() 时引发错误

    // Parts of one ECC system.
    private EllipticCurve curve;
    private Point generator;
    private Point publicKey;
    private BigInteger privateKey;
    
    // We need a curve,a generator point (x,y) and a private key,nA,that will
    // be used to generate the public key.
    public ECC(EllipticCurve c,BigInteger x,BigInteger y,BigInteger nA) {
            
            curve = c;
            generator = new Point(x,y);
            privateKey = nA;
            publicKey = generator.multiply(privateKey);
    }

后来在代码中我尝试使用 Point[] 并且遇到了问题。

            public Point decrypt(Point[] cipher) {
            
            // This is what we subtract out.
            Point sub = cipher[0].multiply(privateKey);
            
            // Subtract out and return.
            System.out.println("sub of "+cipher[1]+" - "+sub);
            return cipher[1].subtract(sub);
    }

解决方法

Point 不能用 BigInteger 声明,我不知道你为什么需要使用 Point。相反,您可以创建您的类 MyPoint 并声明一个 BigInteger 成员字段 xy

class MyPoint {
    BigInteger x,y;
    
    myPoint(BigInteger x,BigInteger y){
        this.x=x;
        this.y=y; 
    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。