diff options
author | Barry Mead <barrymead@cox.net> | 2010-03-02 16:29:07 -0700 |
---|---|---|
committer | Barry Mead <barrymead@cox.net> | 2010-03-02 16:29:07 -0700 |
commit | 67e5093bbf20f840501a6b53c3c26e0e2b1c11f7 (patch) | |
tree | 7c7f75c2f1d15632c74560af0ef2e0804f576031 | |
parent | 455f4b71dea21a7f7907e3b132b716506349bff4 (diff) | |
download | rsa-67e5093bbf20f840501a6b53c3c26e0e2b1c11f7.tar.gz |
more descriptive comments in extended_gcd
-rw-r--r-- | rsa/__init__.py | 7 | ||||
-rw-r--r-- | rsa/fastrsa.py | 7 |
2 files changed, 10 insertions, 4 deletions
diff --git a/rsa/__init__.py b/rsa/__init__.py index d1b85a9..5ed7657 100644 --- a/rsa/__init__.py +++ b/rsa/__init__.py @@ -309,8 +309,11 @@ def find_p_q(nbits): return (p, q) def extended_gcd(a, b): - """Returns a tuple (d, i, j) such that d = gcd(a, b) = ia + jb + """Returns a tuple (r, i, j) such that r = gcd(a, b) = ia + jb """ + # r = gcd(a,b) i = multiplicitive inverse of a mod b + # or j = multiplicitive inverse of b mod a + # Neg return values for i or j are made positive mod b or a respectively # Iterateive Version is faster and uses much less stack space x = 0 y = 1 @@ -325,7 +328,7 @@ def extended_gcd(a, b): (y, ly) = ((ly - (q * y)),y) if (lx < 0): lx += ob #If neg wrap modulo orignal b if (ly < 0): ly += oa #If neg wrap modulo orignal a - return (a, lx, ly) + return (a, lx, ly) #Return only positive values # Main function: calculate encryption and decryption keys def calculate_keys(p, q, nbits): diff --git a/rsa/fastrsa.py b/rsa/fastrsa.py index 869d327..ce63105 100644 --- a/rsa/fastrsa.py +++ b/rsa/fastrsa.py @@ -311,6 +311,9 @@ def find_p_q(nbits): def extended_gcd(a, b): """Returns a tuple (r, i, j) such that r = gcd(a, b) = ia + jb """ + # r = gcd(a,b) i = multiplicitive inverse of a mod b + # or j = multiplicitive inverse of b mod a + # Neg return values for i or j are made positive mod b or a respectively # Iterateive Version is faster and uses much less stack space x = 0 y = 1 @@ -325,7 +328,7 @@ def extended_gcd(a, b): (y, ly) = ((ly - (q * y)),y) if (lx < 0): lx += ob #If negative wrap modulo original b if (ly < 0): ly += oa #If negative wrap modulo original a - return (a, lx, ly) + return (a, lx, ly) #Return only positive values # Main function: calculate encryption and decryption keys def calculate_keys(p, q, nbits): @@ -351,7 +354,7 @@ def calculate_keys(p, q, nbits): if not r == 1: raise Exception("e (%d) and q-1 (%d) are not relatively prime" % (e, q-1)) - (r, qi, j) = extended_gcd(q, p) #Compute coefficent qi + (r, qi, j) = extended_gcd(q, p) #Compute q-inverse coefficent qi if not r == 1: raise Exception("q (%d) and p (%d) are not relatively prime" % (q, p)) |