diff --git a/main.py b/main.py index a4d0cd0..b32dd4e 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import math import random +import time from itertools import combinations @@ -39,7 +40,6 @@ def iterative_extended_euclid(a, b): old_s, s = s, old_s - (quotient * s) old_t, t = t, old_t - (quotient * t) - print(old_r, old_s, old_t) return old_r, old_s, old_t @@ -52,7 +52,6 @@ def modInv(a, m): """ if coPrime(a, m): linear_combination = iterative_extended_euclid(a, m) - print(linear_combination[1] % m) return linear_combination[1] % m else: return 0 @@ -129,17 +128,23 @@ def newKey(a, b, k): def encrypt(message, modN, e): """given a string message, public keys and blockSize, encrypt using RSA algorithms.""" - return pow(message, e, modN) + start = time.time() + ret = pow(message, e, modN) + print("Elapsed time of encryption:", time.time() - start) + return ret def decrypt(secret, modN, d): """reverse function of encrypt""" - return pow(secret, d, modN) + start = time.time() + ret = pow(secret, d, modN) + print("Elapsed time of decryption:", time.time() - start) + return ret if __name__ == '__main__': - n, e, d = newKey(2**40, 2 ** 41, 20) - message = 35274764 + n, e, d = newKey(2**2048, 2 ** 2049, 25) + message = 2**2048 print("original message is {}".format(message)) print("-"*80)