简体   繁体   中英

How can I decode the RSA encryption more efficiently?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM