Bottom Page

Thread Rating:
  • 5 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Can I do this faster?
#1
Hello!

I´m making a RSA-encrypting/decrypting program.

When I encrypt I use a list but t,e and n are big numbers so this take a while. Is there anyway python can do the exact same thing but faster?

wordlist_krypterad = [(t ** e) % n for t in wordlist_ascii_int]

Thanx!
/Gasimoe
Quote
#2
I'd start by making it functional.  Once it works that way, you can look into paralleling it to take advantage of multiple cpu cores.

Without actually testing the code, here's an example of making it functional:
transform = lambda t: (t**e) % n
wordlist_krypterad = map(transform, wordlist_ascii_int)
Quote
#3
https://docs.python.org/3/library/functions.html#pow
Quote
#4
Another way could be using numpy (if your t and n fit into int32) - you are doing exactly same operation on list of numbers, if you transform it to 1-D array, you can manipulate them all at once. I am not sure if there is modular exponentiation in numpy - if not, to avoid overflow (and to speed it) you will need to implement it. With  binary exponentiation it could by quite fast.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Pandas: faster method to count occurrences frame 0 585 May-26-2019, 07:45 PM
Last Post: frame
  Which is Faster, List or SQL AceScottie 11 3,059 Mar-17-2017, 02:31 AM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)