Reputation: 23
For a project I'm decoding the RSA encryption. My code works perfectly, but the check I can do, says its too slow.
I've tested the algorithm and I've concluded that the bottleneck is in the following code:
message = (c**d) % n
Without this, the code runs instantaneously. c is the encrypted message, d is the Modular multiplicative inverse and n = pq. the encrypted message is 783103, so I get that I'm dealing with large numbers, but now it takes around 1 seconds to run. Is there any way to speed this up?
Upvotes: 2
Views: 101
Reputation: 11430
Python's built-in pow() (exponentiation) function 1 takes an optional third argument, the modulus.
That should fix your problem.
This is from en.wikipedia.org/wiki/Modular_exponentiation
Upvotes: 3