License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | Good |
Safe Haskell | None |
Language | Haskell98 |
- generatePrime :: CPRG g => g -> Int -> (Integer, g)
- generateSafePrime :: CPRG g => g -> Int -> (Integer, g)
- isProbablyPrime :: CPRG g => g -> Integer -> (Bool, g)
- findPrimeFrom :: CPRG g => g -> Integer -> (Integer, g)
- findPrimeFromWith :: CPRG g => g -> (g -> Integer -> (Bool, g)) -> Integer -> (Integer, g)
- primalityTestNaive :: Integer -> Bool
- primalityTestMillerRabin :: CPRG g => g -> Int -> Integer -> (Bool, g)
- primalityTestFermat :: Int -> Integer -> Integer -> Bool
- isCoprime :: Integer -> Integer -> Bool
Documentation
generatePrime :: CPRG g => g -> Int -> (Integer, g) Source
generate a prime number of the required bitsize
generateSafePrime :: CPRG g => g -> Int -> (Integer, g) Source
generate a prime number of the form 2p+1 where p is also prime. it is also knowed as a Sophie Germaine prime or safe prime.
The number of safe prime is significantly smaller to the number of prime, as such it shouldn't be used if this number is supposed to be kept safe.
isProbablyPrime :: CPRG g => g -> Integer -> (Bool, g) Source
returns if the number is probably prime. first a list of small primes are implicitely tested for divisibility, then a fermat primality test is used with arbitrary numbers and then the Miller Rabin algorithm is used with an accuracy of 30 recursions
findPrimeFrom :: CPRG g => g -> Integer -> (Integer, g) Source
find a prime from a starting point with no specific property.
findPrimeFromWith :: CPRG g => g -> (g -> Integer -> (Bool, g)) -> Integer -> (Integer, g) Source
find a prime from a starting point where the property hold.
primalityTestNaive :: Integer -> Bool Source
Test naively is integer is prime. while naive, we skip even number and stop iteration at i > sqrt(n)
primalityTestMillerRabin :: CPRG g => g -> Int -> Integer -> (Bool, g) Source
Miller Rabin algorithm return if the number is probably prime or composite. the tries parameter is the number of recursion, that determines the accuracy of the test.