

The problem is when I try encrypting large files (10kB of text file) I take the block size of 32 byte when reading the file and encrypting it > f = open('10kb','rb') If on Python 3.I have been using pycrypto module for encryption and decryption with RSA key pair and algorithm. I've also switched to a "lazy" join when joined from a generator. You can avoid converting s to a list in order to iterate character by character: ''.join(str(chr(encrypt_block(ord(x)))) for x in s) I also wonder if adding an LRU cache via functools.lru_cache() would make an impact - probably not, but please experiment with that. Here is a simple benchmark for some a and m which have a modular inverse of 16013: In : a = 108 ** 151ġ00000 loops, best of 3: 5.62 µs per loop Raise Exception('modular inverse does not exist') We can apply this Extended GCD algorithm recursive implementation which shows quite a dramatic speed improvement (at least on my machine): def egcd(a, b): I think your Modular Inverse implementation is slow. Print("Decrypted message: " + dec + "\n") Print("Encrypted message: " + enc + "\n") S = input("Enter a message to encrypt: ") If m = None: print('No modular multiplicative inverse for block ' + str(c) + '.') If c = None: print('No modular multiplicative inverse for block ' + str(m) + '.')


Print("Your private key is a pair of numbers (d=" + str(d) + ", n=" + str(n) + ").\n") Print("\nYour public key is a pair of numbers (e=" + str(e) + ", n=" + str(n) + ").\n") Print("Choose an e from a below coprimes array:\n") If gcd(a, x) = 1 and modinv(x,phi) != None: Print("Euler's function (totient) : " + str(phi) + "\n")

What do you think about my Python 3 implementation of the RSA algorithm? What's the performance of this program? try:
