commit 3627224d4d0c4b02ed22cb32f8fe88addd944687
parent e51aed47ccf56e3f1dc0b0be13cbec5afd1e7a52
Author: Shivakumar <[email protected]>
Date: Sat, 28 Jun 2025 16:46:35 +0530
add docs to keys.py
Diffstat:
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/ecc/keys.py b/ecc/keys.py
@@ -1,17 +1,44 @@
+# Generation of Private Key and Public Key.
+#
+# Private Key - A random number (k) in between 1 and n,
+# where n is order of generator point G.
+#
+# Public Key - The point P = k * G, on the elliptic
+# curve with Field E(Z/pZ)
+#
+# Here, we use the randbelow function from secrets
+# to get a random number in between 1 and n(curve.n).
+# Here, n is ord(G). G is the generator point, and
+# ord(n) is the no. of points G can generate. Usually
+# n is |E(Z/pZ)|, as we choose the generator point to
+# get all the points in the Field E(Z/pZ).
+#
+# The random number we get is our Private Key. And we
+# multiply the random number with the generator point
+# G to get our Public Key.
+#
+# secret -> random number between (1, n)
+# public_key -> point
+#
+# private_key = PrivateKey(secret, curve)
+#
+# public_key = private_key.public_key()
+# public_key = secret * G
+
+
from secrets import randbelow
from .point import Point
class PublicKey:
def __init__(self, point: Point, curve):
- if not isinstance(point, Point):
- raise TypeError("Public Key must be a Point.")
-
self.point = point
self.curve = curve
def __repr__(self):
+ if (self.point.x, self.point.y) == (None, None):
+ return "PublicKey(Point(infinity))"
return f"PublicKey(\n\tx={hex(self.point.x.num)}, \n\ty={hex(self.point.y.num)}\n)"