Package Crypto :: Package Util :: Module number
[hide private]
[frames] | no frames]

Module number

Functions [hide private]
 
size(N)
size(N:long) : int Returns the size of the number N in bits.
 
getRandomNumber(N, randfunc=None)
getRandomNumber(N:int, randfunc:callable):long Return a random N-bit number.
 
GCD(x, y)
GCD(x:long, y:long): long Return the GCD of x and y.
 
inverse(u, v)
inverse(u:long, u:long):long Return the inverse of u mod v.
 
getPrime(N, randfunc=None)
getPrime(N:int, randfunc:callable):long Return a random N-bit prime number.
 
isPrime(N, randfunc=None)
isPrime(N:long, randfunc:callable):bool Return true if N is prime.
 
long_to_bytes(n, blocksize=0)
long_to_bytes(n:long, blocksize:int) : string Convert a long integer to a byte string.
 
bytes_to_long(s)
bytes_to_long(string) : long Convert a byte string to a long integer.
 
long2str(n, blocksize=0)
 
str2long(s)
 
_import_Random()
Variables [hide private]
  __revision__ = '$Id$'
  _fastmath = None
hash(x)
  sieve = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 4...
  __package__ = 'Crypto.Util'
Function Details [hide private]

getRandomNumber(N, randfunc=None)

 

getRandomNumber(N:int, randfunc:callable):long Return a random N-bit number.

If randfunc is omitted, then Random.new().read is used.

NOTE: Confusingly, this function does NOT return N random bits; It returns a random N-bit number, i.e. a random number between 2**(N-1) and (2**N)-1.

This function is for internal use only and may be renamed or removed in the future.

getPrime(N, randfunc=None)

 

getPrime(N:int, randfunc:callable):long Return a random N-bit prime number.

If randfunc is omitted, then Random.new().read is used.

isPrime(N, randfunc=None)

 

isPrime(N:long, randfunc:callable):bool Return true if N is prime.

If randfunc is omitted, then Random.new().read is used.

long_to_bytes(n, blocksize=0)

 

long_to_bytes(n:long, blocksize:int) : string Convert a long integer to a byte string.

If optional blocksize is given and greater than zero, pad the front of the byte string with binary zeros so that the length is a multiple of blocksize.

bytes_to_long(s)

 

bytes_to_long(string) : long Convert a byte string to a long integer.

This is (essentially) the inverse of long_to_bytes().


Variables Details [hide private]

sieve

Value:
[2,
 3,
 5,
 7,
 11,
 13,
 17,
 19,
...