简体   繁体   English

椭圆曲线上的零点

[英]Point zero on an elliptic curve

I am working on a library that allows me to work with elliptic curves. 我正在使用允许使用椭圆曲线的库。 It is still at embryonic state, and so far it only consists of two classes, EllipticCurve and Point . 它仍然处于萌芽状态,到目前为止,它仅由EllipticCurvePoint两类组成。

Right now I'm implementing the basic operations of existence, belonging, sum, reflection, etc. 现在,我正在实现存在,所有,求和,反射等基本操作。

Unfortunately, I'm stuck now that I have to implement the concept of zero, ie, the point of the elliptic curve E crossing the line through P and -P, where P = (x,y) and -P = (x,-y). 不幸的是,我现在不得不实施零概念,即椭圆曲线E的点穿过P和-P的直线,其中P =(x,y)和-P =(x, -y)。 So, my question could be rephrased as "how do I implement a point at infinity?" 因此,我的问题可以改写为“如何实现无穷远点?”

Here's part of the Point class so far: 到目前为止,这是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
     */
}

PS: I am aware of the existence of java.security.spec.EllipticCurve, but since I'm going to use this class mostly for mathematical purposes, I felt the need to create my personal library ex novo . PS:我知道java.security.spec.EllipticCurve的存在,但是由于我主要是出于数学目的使用此类,所以我觉得有必要从头创建我的个人库。

There is no way to represent infinity per se using BigDecimal . 使用BigDecimal本身无法表示无穷大。 The only way in Java I know is: 我知道的Java唯一方法是:

Double.POSITIVE_INFINITY;

or Integer , Float etc. You also can't take valueOf from the above, since it will throw a NumberFormatException . IntegerFloat等。您也不能从上面获取valueOf ,因为它将抛出NumberFormatException

You can use a workaround, ie a very large value that you know will always be larger than any other. 您可以使用一种解决方法,即您知道一个非常大的值将始终大于其他任何值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM