diff --git a/hill.lisp b/hill.lisp index 347b21a..10f0746 100644 --- a/hill.lisp +++ b/hill.lisp @@ -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: diff --git a/shift-affine.lisp b/shift-affine.lisp index 13549e8..fde6706 100644 --- a/shift-affine.lisp +++ b/shift-affine.lisp @@ -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))