6.1 Crypto.Util.number

This module contains various number-theoretic functions.

GCD(x,y)
Return the greatest common divisor of x and y.

getPrime(N, randfunc)
Return an N-bit random prime number, using random data obtained from the function randfunc. randfunc must take a single integer argument, and return a string of random data of the corresponding length; the get_bytes() method of a RandomPool object will serve the purpose nicely, as will the read() method of an opened file such as /dev/random.

getRandomNumber(N, randfunc)
Return an N-bit random number, using random data obtained from the function randfunc. As usual, randfunc must take a single integer argument and return a string of random data of the corresponding length.

inverse(u, v)
Return the inverse of u modulo v.

isPrime(N)
Returns true if the number N is prime, as determined by a Rabin-Miller test.