From d98a2f1cd702c08667841b98918a7e1b027d1ce3 Mon Sep 17 00:00:00 2001 From: Barry Mead Date: Tue, 16 Feb 2010 12:37:28 -0700 Subject: Made extended_gcd not return any negative values for either i or j --- rsa/__init__.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rsa/__init__.py') diff --git a/rsa/__init__.py b/rsa/__init__.py index 2469136..f6f1e74 100644 --- a/rsa/__init__.py +++ b/rsa/__init__.py @@ -328,6 +328,7 @@ def extended_gcd(a, b): y = 1 lx = 1 ly = 0 + la = a lb = b #Remember modulus (to remove negs) while b != 0: q = long(a/b) @@ -335,6 +336,7 @@ def extended_gcd(a, b): (x, lx) = ((lx - (q * x)),x) (y, ly) = ((ly - (q * y)),y) if (lx < 0): lx += lb #No Negative return values + if (ly < 0): ly += la return (a, lx, ly) # Main function: calculate encryption and decryption keys -- cgit v1.2.1