CLI interface + restructuration + precision fixes Fermat Factorization

This commit is contained in:
2026-01-11 17:58:36 +01:00
parent ada11a25d2
commit 6689ff8ae2
11 changed files with 117 additions and 50 deletions

36
app/FactorizationUI.hs Normal file
View File

@@ -0,0 +1,36 @@
module FactorizationUI (run) where
import Utils (askChoice, askNumber)
import Factorization (fermatFactorization, pollardPminus1)
run :: IO ()
run = do
putStrLn "Factorization"
putStrLn "1) Fermat factorization"
putStrLn "2) Pollard p-1"
choice <- askChoice 2
case choice of
1 -> fermatUI
2 -> pollardUI
_ -> error "Impossible"
fermatUI :: IO ()
fermatUI = do
n <- askNumber "Enter an integer n > 1:"
let (p, q) = fermatFactorization n
putStrLn ("n = " ++ show n)
putStrLn ("p = " ++ show p)
putStrLn ("q = " ++ show q)
pollardUI :: IO ()
pollardUI = do
n <- askNumber "Enter an integer n > 1:"
b <- askNumber "Enter the bound B:"
case pollardPminus1 n b of
Just factor -> do
putStrLn ("Found factor: " ++ show factor)
putStrLn ("Other factor: " ++ show (n `div` factor))
Nothing ->
putStrLn "Failed to find a factor (try a different B or method)."