🔮
Roll your own crypto
  • 🗞️Roll your own crypto* 🔮
  • 👩‍🏫Introduction to ECC
  • 🕓Galois Fields
  • ➰Elliptic Curve in Python
  • 🎯Representing a point
  • ➰Group Theory
  • ➕Point Addition in Python
  • ✖️Scalar Multiplication in Python
  • 🖋️ECDSA
  • 🎮Quiz: The Playstation 3 Hack
  • ❤️Conclusion
Powered by GitBook
On this page

Was this helpful?

Representing a point

PreviousElliptic Curve in PythonNextGroup Theory

Last updated 1 year ago

Was this helpful?

We call a Point an element of the elliptic curve group, which we can represent with its coordinates. Let's define a Point class to encapsulate the xxx and yyy coordinates in the generalised curve equation of y2=x3+ax+by^2 = x^3 + ax + by2=x3+ax+b.

from typing import Optional

@dataclass
class Point:
    x: Optional[int]
    y: Optional[int]

    curve: EllipticCurve

    def __post_init__(self):
        # Ignore validation for I
        if self.x is None and self.y is None:
            return

        # Encapsulate int coordinates in FieldElement
        self.x = FieldElement(self.x, self.curve.field)
        self.y = FieldElement(self.y, self.curve.field)

        # Verify if the point satisfies the curve equation
        if self not in self.curve:
            raise ValueError

Point-compression: To reduce the storage size for a curve point, one can also store a sign and thex coordinate. It is then possible to reconstruct the y by calculating sign * sqrt(x^3+a*x+b).

Ref:

🎯
https://bitcoin.stackexchange.com/a/29905