Warm tip: This article is reproduced from serverfault.com, please click

How can I decode the RSA encryption more efficiently?

发布于 2020-12-04 20:01:15

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?

Questioner
Casper
Viewed
0
Jeffrey 2020-12-05 04:04:35

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