commit f3192e95ed2df1c61e1a469c41ea88eefb5b143b
parent 2e78d1996c9d4ed2b6b477f1a9e8ef05d4099742
Author: Shivakumar <[email protected]>
Date: Wed, 25 Jun 2025 23:35:41 +0530
make curve.py and add curve definition
Diffstat:
1 file changed, 33 insertions(+), 0 deletions(-)
diff --git a/ecc/curve.py b/ecc/curve.py
@@ -0,0 +1,33 @@
+
+
+class Curve:
+
+
+ def __init__(self, a, b, P, G, n, h=1):
+
+ """
+ parameters:
+ a, b : Curve parameters (y^2 = x^3 + ax + b).
+ P : Prime modulo for finite Field.
+ G : Generator point.
+ n : Order of Generator point.
+ h : Co-factor (usually 1).
+ """
+
+ self.a = a
+ self.b = b
+
+ self.P = P
+ self.G = G
+ self.n = n
+
+ # Check if the curve is singular
+ if 4*(a**2) + 27*(b**2) == 0:
+ raise ValueError("This is a singular curve (discriminant is zero). Choose different parameters for the curve.")
+
+
+ def __repr__(self):
+
+ return f"Curve: y^2 = x^3 + {self.a}x + {self.b} over the Field(Z/{self.P}Z)."
+
+