Miller Rabin primality test
This commit is contained in:
@@ -1,14 +1,6 @@
|
||||
module TonelliShanks (tonelliShanks) where
|
||||
|
||||
import ModularArithmeticUtils (modExp, modMul, legendre)
|
||||
|
||||
-- Factor p-1 as q * 2^s, where q is odd
|
||||
factorOutTwos :: Integer -> (Integer, Integer)
|
||||
factorOutTwos n = go n 0
|
||||
where
|
||||
go x s
|
||||
| even x = go (x `div` 2) (s + 1)
|
||||
| otherwise = (x, s)
|
||||
import ModularArithmeticUtils (modExp, modMul, legendre, factorOutTwos)
|
||||
|
||||
-- Tonelli-Shanks algorithm: find x such that x^2 = n (mod p)
|
||||
-- Returns Just x if it exists, Nothing otherwise.
|
||||
|
||||
Reference in New Issue
Block a user