Skip to content

Instantly share code, notes, and snippets.

@enigbe
Last active February 12, 2022 11:40
Show Gist options
  • Save enigbe/1a3961e63c8256a07c16c2dbcc6e66f9 to your computer and use it in GitHub Desktop.
Save enigbe/1a3961e63c8256a07c16c2dbcc6e66f9 to your computer and use it in GitHub Desktop.
Elliptic Curve Point in a Finite Field
from finite_field_element import FiniteFieldElement
class ECPoint:
"""
A point on an elliptic curve
"""
def __init__(
self, x: FiniteFieldElement, y: FiniteFieldElement, a: FiniteFieldElement, b: FiniteFieldElement
) -> Self:
"""
Instantiates a point on an elliptic curve in a finite field
defined by y^2 = x^3 + ax + b
Args:
x : x-coordinate value
y : y-coordinate value
a : constant coefficient of x where y^2 = x^3 + ax + b
b : constant where y^2 = x^3 + ax + b
"""
self.a = a
self.b = b
self.x = x
self.y = y
# Point at Infinity
if self.x is None and self.y is None:
return
if (self.y ** 2) != (self.x ** 3) + (a * x) + b:
raise ValueError(f'({x}, {y}) is not on the curve')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment