From d688640a41a7ec9a2e7f0a5e1901fc2f0350e64f Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Fri, 20 Sep 2019 12:16:58 +0200 Subject: [PATCH] Replaced ** % with pow. Much faster. Now allows for higher primes --- week4.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/week4.py b/week4.py index 4874c5c..48a6eeb 100644 --- a/week4.py +++ b/week4.py @@ -34,7 +34,7 @@ class ElGamal: return key def gen(self, sk): - h = (self.gen_**sk) % self.order + h = pow(self.gen_, sk, self.order) self.sk = sk self.pk = (self.gen_, h) return self.pk @@ -44,20 +44,20 @@ class ElGamal: r = SystemRandom().randint(1, self.order) g, h = pk - s = (h**r) % self.order - p = (g**r) % self.order + s = pow(h, r, self.order) + p = pow(g, r, self.order) c = s * m return c, p def dec(self, c): c1, c2 = c - h = (c2**self.sk) % self.order + h = pow(c2, self.sk, self.order) m = c1 / h return m def ogen(self): s = SystemRandom().randint(1, self.order) - h = s**2 % self.order + h = pow(s, 2, self.order) return self.gen_, h @@ -111,7 +111,7 @@ class Bob: def run(donor : BloodType, recipient : BloodType): - p = 35977 + p = 15485863 q = 2 * p + 1 g = SystemRandom().randint(2, q)