diff --git a/ModularArithmeticUtils.hs b/ModularArithmeticUtils.hs index 0223439..5fa0cb8 100644 --- a/ModularArithmeticUtils.hs +++ b/ModularArithmeticUtils.hs @@ -1,4 +1,4 @@ -module ModularArithmeticUtils (modExp, modMul, legendre, factorOutTwos) where +module ModularArithmeticUtils (modExp, modMul, legendre, factorOutTwos, jacobi) where import Data.Bits (testBit, shiftR) diff --git a/SolaveyStrassen.hs b/SolaveyStrassen.hs new file mode 100644 index 0000000..e9c1421 --- /dev/null +++ b/SolaveyStrassen.hs @@ -0,0 +1,28 @@ +module SolaveyStrassen (solaveyStrassen) where + +import ModularArithmeticUtils (modExp, jacobi) +import System.Random (randomRIO) + + +solaveyStrassen :: Integer -> Integer -> IO Bool +solaveyStrassen n k + | n < 2 = return False + | n == 2 = return True + | even n = return False + | otherwise = go k + where + expHalf = (n - 1) `div` 2 + + go 0 = return True + go i = do + a <- randomRIO (2, n - 2) + if gcd a n /= 1 + then return False + else do + let x = modExp a expHalf n + j = jacobi a n `mod` n + + if x /= j + then return False + else go (i - 1) +