Files
haskell-math/app/PrimesUI.hs
2026-01-12 13:33:29 +01:00

30 lines
794 B
Haskell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module PrimesUI (run) where
import Utils (askChoice, askNumber)
import Primes (fermatPrimeTest, millerRabin, solovayStrassen)
run :: IO ()
run = do
putStrLn "Primality tests"
putStrLn "1) Fermat primality test"
putStrLn "2) MillerRabin test"
putStrLn "3) SolovayStrassen test"
choice <- askChoice 3
n <- askNumber "Enter integer n > 1 to test for primality:"
k <- askNumber "Enter security parameter k (number of rounds):"
result <- case choice of
1 -> fermatPrimeTest n k
2 -> millerRabin n k
3 -> solovayStrassen n k
_ -> error "Impossible choice"
putStrLn ("n = " ++ show n)
putStrLn ("k = " ++ show k)
if result
then putStrLn "Result: probably prime."
else putStrLn "Result: composite."