ecc

Elliptic Curve Cryptograpy library from scratch in python.
Log | Files | Refs | README | LICENSE

commit 2e78d1996c9d4ed2b6b477f1a9e8ef05d4099742
parent a7d8f9972ad8a6b97c8cd295dcacab1794275741
Author: Shivakumar <[email protected]>
Date:   Wed, 25 Jun 2025 23:22:28 +0530

add scalar multiplication and division to Field Operation

Diffstat:
Mecc/field.py | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/ecc/field.py b/ecc/field.py @@ -18,7 +18,6 @@ # a^k = (a^(p-1))^q * a^r (mod p) # a^k = a^r (mod p) # a^k = a^(k mod p-1) (mod p) -# class FieldElement: @@ -63,6 +62,23 @@ class FieldElement: return self.num == other.num and self.prime == other.prime + + def __rmul__(self, coefficient): + + res = (coefficient * self.num) % self.prime + return FieldElement(res, self.prime) + + + def __truediv__(self, other): + + if self.prime != other.prime: + raise TypeError("Can not divide the elements of different Field.") + + inv = pow(other.num, -1, self.prime) + num = (self.num * inv) % self.prime + + return FieldElement(num, self.prime) + def __pow__(self, exponent: int):