primality tests UI

This commit is contained in:
2026-01-12 13:33:29 +01:00
parent 6689ff8ae2
commit 2e0cbfe714
3 changed files with 33 additions and 2 deletions

29
app/PrimesUI.hs Normal file
View File

@@ -0,0 +1,29 @@
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."