Add support for signed modular inversion.

This commit is contained in:
2018-12-30 17:14:11 -08:00
parent a6a82773d3
commit 130a87ef43
3 changed files with 105 additions and 16 deletions

View File

@@ -309,5 +309,22 @@ modinvTest size memoryIn =
("c", showX c)]
in if c == 0
then attempt memory2
else assert ((c < b) && ((a * c) `mod` b == 1)) (res, c, memory2)
in attempt memoryIn
else assert (c < b) $
assert ((a * c) `mod` b == 1) $
(res, c, memory2)
in attempt memoryIn
smodinvTest :: Test
smodinvTest size memoryIn =
let attempt memory0 =
let (a, memory1) = genSign (generateNum memory0 "a" size)
(b, memory2) = generateNum memory1 "b" size
c = recipModInteger a b
res = Map.fromList [("a", showX a), ("b", showX b),
("c", showX c)]
in if c == 0
then attempt memory2
else assert (c < b) $
assert ((a * c) `mod` b == 1) $
(res, c, memory2)
in attempt memoryIn