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 .
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). So, my question could be rephrased as "how do I implement a point at infinity?"
Here's part of the Point class so far:
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 .
There is no way to represent infinity per se using BigDecimal
. The only way in Java I know is:
Double.POSITIVE_INFINITY;
or Integer
, Float
etc. You also can't take valueOf
from the above, since it will throw a NumberFormatException
.
You can use a workaround, ie a very large value that you know will always be larger than any other.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.