summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Mead <barrymead@cox.net>2010-02-16 12:37:55 -0700
committerBarry Mead <barrymead@cox.net>2010-02-16 12:37:55 -0700
commitedf743f57753a044850e92b7f4e347a4853d7f30 (patch)
tree69f838b5e46b82c14a76981c7270f5d43b7b5ec0
parent350827e5dcee8b9662950269825440ea7750f55f (diff)
downloadrsa-git-edf743f57753a044850e92b7f4e347a4853d7f30.tar.gz
Made extended_gcd not return any negative values for either i or j
-rw-r--r--rsa/fastrsa.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/rsa/fastrsa.py b/rsa/fastrsa.py
index 516f4ce..4716fca 100644
--- a/rsa/fastrsa.py
+++ b/rsa/fastrsa.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