commit 9f03e4db852419311e53cff3583b7716d59606ca
parent dc19ac61f17feb796d06044e817775e3cc975190
Author: Shivakumar <[email protected]>
Date: Wed, 25 Jun 2025 23:40:12 +0530
add scalar multiplication to Point
Diffstat:
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/ecc/point.py b/ecc/point.py
@@ -56,3 +56,32 @@ class Point:
return Point(None, None, self.curve)
+ def __eq__(self, other):
+
+ if not isinstance(other, Point):
+ return False
+
+ return self.x == other.x and self.y == other.y and self.curve == other.curve
+
+
+ def __rmul__(self, coefficient):
+
+ result = Point(None, None, self.curve)
+ addend = self
+
+ # Double and Add Algorithm
+ while coefficient:
+ if coefficient & 1:
+ result = result + addend
+ addend = addend + addend
+ coefficient >>= 1
+
+ return result
+
+
+ def __repr__(self):
+
+ if self.x is None:
+ return "Point(infinity)"
+
+ return f"Point(\n\t{self.x.num}, \n\t{self.y.num}\n)"