summaryrefslogtreecommitdiff
path: root/rsa/__init__.py
diff options
context:
space:
mode:
authorBarry Mead <barrymead@cox.net>2010-02-16 12:37:28 -0700
committerBarry Mead <barrymead@cox.net>2010-02-16 12:37:28 -0700
commitd98a2f1cd702c08667841b98918a7e1b027d1ce3 (patch)
tree428092a44a340eb4a3d768fa1f52a87837dc681f /rsa/__init__.py
parente63f787a3715d4068b305aa6110ded6d7ec78eb1 (diff)
downloadrsa-d98a2f1cd702c08667841b98918a7e1b027d1ce3.tar.gz
Made extended_gcd not return any negative values for either i or j
Diffstat (limited to 'rsa/__init__.py')
-rw-r--r--rsa/__init__.py2
1 files changed, 2 insertions, 0 deletions
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