Dixon factorization, automatic parameters

This commit is contained in:
sam.hadow committed 2026-10-13 17:26:33 +02:00
1 parent 76b89be699
commit bac5cb38bc
3 files changed
+89 -40

No files matched your search

+23 -3
View File
@@ -3,7 +3,7 @@ module FactorizationUI (run) where
import System.Exit (exitSuccess)
import Utils (askChoice, askNumber)
import Factorization
( fermatFactorization, pollardPminus1, dixon
( fermatFactorization, pollardPminus1, dixon, dixonDefaultParams
, gnfsWith, GNFSParams(..), defaultParams
)
@@ -45,13 +45,33 @@ pollardUI = do
dixonUI :: IO ()
dixonUI = do
putStrLn "Dixon"
putStrLn "Factors a composite n (not a prime, a perfect square or a prime power)."
putStrLn "Practical for n up to roughly 22 digits; 24 digits already takes about a minute."
n <- askNumber "Enter an integer n > 1:"
b <- askNumber "Enter the bound B:"
x <- askNumber "Enter the max random integer x:"
putStrLn "Parameters:"
putStrLn "1) Automatic (recommended)"
putStrLn "2) Custom"
mode <- askChoice 2
let (autoB, autoX) = dixonDefaultParams n
(b, x) <- case mode of
1 -> return (autoB, autoX)
_ -> do
putStrLn ("Automatic values for this n: bound B = " ++ show autoB
++ ", max x = " ++ show autoX)
b' <- askNumber "Enter the bound B:"
x' <- askNumber "Enter the max integer x (the search starts at floor(sqrt n) + 1):"
return (b', x')
putStrLn "Running Dixon (this may take a while)..."
case dixon n b x of
Left err -> do
putStrLn ("Error: " ++ err)
if mode == 1
then putStrLn "Check that n is composite and not a perfect square or a prime power."
else return ()
Right (p, q) -> do
putStrLn ("n = " ++ show n)
putStrLn ("p = " ++ show p)