Generating Large Prime Numbers with Py Crypto

I'm trying to generate a large prime number (2048 bits) using the crypto library in python in order to implement RSA. However, I do not really understand the syntax of the getPrime() function. I currently have:

from Crypto.Util import number

n_length = 2048

primeNum = number.getPrime(n_length, randFunc)

I don't understand what the randFunc is supposed to be in the getPrime function.

6

1 Answer

n_length is the "size" of the prime number. It will return a number around 2^n_length. randFunc is a callable function that accepts a single argument N and then returns a string of N random bytes. (os.urandom is an example of this). In most cases, randFunc can (and should) be omitted, since the default is PyCrypto's own random number generator.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest