SolaveyStrassen
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
module ModularArithmeticUtils (modExp, modMul, legendre, factorOutTwos) where
|
module ModularArithmeticUtils (modExp, modMul, legendre, factorOutTwos, jacobi) where
|
||||||
|
|
||||||
import Data.Bits (testBit, shiftR)
|
import Data.Bits (testBit, shiftR)
|
||||||
|
|
||||||
|
|||||||
28
SolaveyStrassen.hs
Normal file
28
SolaveyStrassen.hs
Normal file
@@ -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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user