1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- class Point:
- def __init__(self, x, y, curve):
- self.x = x
- self.y = y
- self.curve = curve
- def isNone(self):
- return self.x is None or self.y is None or self.curve is None
- def coords(self):
- return self.x, self.y
-
- def getIncline(self, point):
- m = 0
- cur = self.curve
- x1, y1 = self.coords()
- x2, y2 = point.coords()
- if self.x == point.x:
-
- c = self.curve
- m = (3 * x1 * x1 + cur.a) * cur.inverseMod(2 * y1, curve.p)
- else:
-
- m = (y1 - y2) * cur.inverseMod(x1 - x2, cur.p)
- return m
-
- def __add__(self, point):
-
-
- if self.isNone():
- return point
- if point.isNone():
- return self
- if self.x == point.x and self.y != point.y:
-
- return Point()
-
- m = self.getIncline(point)
-
- rx = m * m - self.x - point.x
- ry = self.y + m * (rx - self.x)
- return Point(
- curve = self.curve,
- x = rx % self.curve.p,
- y = -ry % self.curve.p,
- )
-
- def __neg__(self):
- return Point(
- curve = self.curve,
- x = self.x,
- y = -self.y % curve.p,
- )
-
- def __eq__(self, point):
-
- return self.x == point.x
-
|