CLI interface + restructuration + precision fixes Fermat Factorization
This commit is contained in:
36
app/FactorizationUI.hs
Normal file
36
app/FactorizationUI.hs
Normal 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)."
|
||||
Reference in New Issue
Block a user