gpt4 book ai didi

java - 椭圆曲线上的零点

转载 作者:行者123 更新时间:2023-11-30 08:19:01 26 4
gpt4 key购买 nike

我正在开发一个允许我使用椭圆曲线的库。它还处于萌芽状态,到目前为止它只包含两个类,EllipticCurvePoint

现在我正在实现存在、归属、总和、反射等基本操作。

不幸的是,我现在陷入困境,我必须实现零的概念,即椭圆曲线 E 与 P 和 -P 相交的点,其中 P = (x,y) 和 -P = (x,-y)。所以,我的问题可以改写为“如何实现无穷远点?”

这是到目前为止 Point 类的一部分:

public class Point implements Comparable<Point> {
private static final BigDecimal MINUSONE = new BigDecimal(-1);

private BigDecimal x;
private BigDecimal y;
private EllipticCurve e;

public Point(BigDecimal x, BigDecimal y, EllipticCurve e) {
if(x != null && y != null && e != null) {
if(liesOn(x,y,e)) {
this.x = x;
this.y = y;
this.e = e;
}
}
}

public Point reflect() {
return new Point(x,y.multiply(MINUSONE),e);
}

public Point add(Point o) {
if(this.e == o.getE()) {
if(this == o) {
return this.multiply(2);
}
if(o == this.reflect()) {
return /*THE INFAMOUS ZERO POINT*/;
}

BigDecimal a;
BigDecimal b;

/*
* computation I still haven't implemented
*/

return new Point(a,b,e);
}
}
/*
* other methods
*/
}

P.S.:我知道 java.security.spec.EllipticCurve 的存在,但由于我主要将此类用于数学目的,所以我觉得有必要创建我的个人库ex novo.

最佳答案

无法使用 BigDecimal 来表示无穷大本身。我所知道的 Java 中唯一的方法是:

Double.POSITIVE_INFINITY;

IntegerFloat等。您也不能从上面获取valueOf,因为它会抛出NumberFormatException

您可以使用解决方法,即。 e.一个非常大的值,您知道它总是比任何其他值都大。

关于java - 椭圆曲线上的零点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29231792/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com