使用 Point 和 BigInteger
Using Point and BigInteger
如何将 Java 中的点与 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
。相反,您可以创建 class MyPoint
并声明 BigInteger
成员字段 x
和 y
.
class MyPoint {
BigInteger x, y;
myPoint(BigInteger x, BigInteger y){
this.x=x;
this.y=y;
}
}
如何将 Java 中的点与 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
。相反,您可以创建 class MyPoint
并声明 BigInteger
成员字段 x
和 y
.
class MyPoint {
BigInteger x, y;
myPoint(BigInteger x, BigInteger y){
this.x=x;
this.y=y;
}
}