primality tests UI

This commit is contained in:
Sam HADOW committed 2026-01-12 13:33:29 +01:00
1 parent 6689ff8ae2
commit 2e0cbfe714
3 files changed
+33 -2

No files matched your search

+3 -2
View File
@@ -2,18 +2,19 @@ module Main where
import Utils (askChoice) import Utils (askChoice)
import qualified FactorizationUI import qualified FactorizationUI
import qualified PrimesUI
main :: IO () main :: IO ()
main = do main = do
putStrLn "Haskell Math Toolkit" putStrLn "Haskell Math Toolkit"
putStrLn "1) Factorization" putStrLn "1) Factorization"
putStrLn "2) Modular square root (not yet implemented)" putStrLn "2) Modular square root (not yet implemented)"
putStrLn "3) Primality test (not yet implemented)" putStrLn "3) Primality tests"
choice <- askChoice 3 choice <- askChoice 3
case choice of case choice of
1 -> FactorizationUI.run 1 -> FactorizationUI.run
2 -> putStrLn "Modular square root: not implemented yet." 2 -> putStrLn "Modular square root: not implemented yet."
3 -> putStrLn "Primality test: not implemented yet." 3 -> PrimesUI.run
_ -> error "Impossible" _ -> error "Impossible"
+29
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) Miller–Rabin test"
putStrLn "3) Solovay–Strassen 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."
+1
View File
@@ -41,6 +41,7 @@ executable haskell-math
main-is: Main.hs main-is: Main.hs
other-modules: other-modules:
FactorizationUI FactorizationUI
PrimesUI
Utils Utils
build-depends: build-depends:
base ^>=4.18.2.1, base ^>=4.18.2.1,