implement Tonelli Shanks
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import Text.Read (readMaybe)
|
||||
import System.Exit (exitSuccess)
|
||||
import Data.Bits
|
||||
import Utils (askNumber)
|
||||
import ModularArithmeticUtils (modExp)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
@@ -41,10 +41,3 @@ pollardP1WithParams n a b = go a 2
|
||||
else if d == n
|
||||
then Nothing -- Found n itself, try with different parameters
|
||||
else go newA (k + 1)
|
||||
|
||||
-- Modular exponentiation: compute a^b mod m
|
||||
modExp :: Integer -> Integer -> Integer -> Integer
|
||||
modExp b 0 m = 1
|
||||
modExp b e m = t * modExp ((b * b) `mod` m) (shiftR e 1) m `mod` m
|
||||
where t = if testBit e 0 then b `mod` m else 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user