Fix the modular-multiplicative-inverse
This commit is contained in:
parent
1f86243917
commit
f154ef9b35
@ -145,7 +145,10 @@ return a cons of (x . y) such char x * N1 + y * N2 = GCD."
|
||||
"Find the modular multiplicative inverse of N with respect to M. That is, some
|
||||
integer i such that (N * i) mod M = 1."
|
||||
(destructuring-bind (gcd (x . y))
|
||||
(multiple-value-list (extended-gcd n m))
|
||||
(multiple-value-list (extended-gcd (if (minusp n)
|
||||
(+ 26 n)
|
||||
n)
|
||||
m))
|
||||
(declare (ignorable y))
|
||||
(unless (= 1 gcd)
|
||||
(error "N and M must be coprime. N: ~d, M: ~d" n m))
|
||||
@ -428,5 +431,5 @@ be the same value originally used to encrypt the text."
|
||||
'string))
|
||||
|
||||
;; Local Variables:
|
||||
;; jinx-local-words: "adjugate cofactor cofactors det plaintext prandom unnessesary xorshift"
|
||||
;; jinx-local-words: "adjugate cofactor cofactors coprime det plaintext prandom unnessesary xorshift"
|
||||
;; End:
|
||||
|
@ -61,7 +61,10 @@ return a cons of (x . y) such char x * N1 + y * N2 = GCD."
|
||||
"Find the modular multiplicative inverse of N with respect to M. That is, some
|
||||
integer i such that (N * i) mod M = 1."
|
||||
(destructuring-bind (gcd (x . y))
|
||||
(multiple-value-list (extended-gcd n m))
|
||||
(multiple-value-list (extended-gcd (if (minusp n)
|
||||
(+ 26 n)
|
||||
n)
|
||||
m))
|
||||
(declare (ignorable y))
|
||||
(unless (= 1 gcd)
|
||||
(error "N and M must be coprime. N: ~d, M: ~d" n m))
|
||||
|
Loading…
Reference in New Issue
Block a user