【发布时间】:2015-03-26 18:55:33
【问题描述】:
我正在开发一个允许我使用椭圆曲线的库。它还处于萌芽状态,目前只包含EllipticCurve和Point两个类。
现在我正在实现存在、归属、求和、反射等基本操作。
不幸的是,我现在被困住了,我必须实现零的概念,即椭圆曲线 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。
【问题讨论】:
标签: java elliptic-curve