diff options
author | Sybren A. St?vel <sybren@stuvel.eu> | 2011-06-20 00:49:31 +0200 |
---|---|---|
committer | Sybren A. St?vel <sybren@stuvel.eu> | 2011-06-20 00:49:31 +0200 |
commit | 35212ea3acf09c3483bf64d7fbc4e6cacb346270 (patch) | |
tree | 249a2f68325886936532aab4dac27e182dae0ac3 | |
parent | 6a111f028f88463f53169c19d4db251b4e5d0c24 (diff) | |
download | rsa-35212ea3acf09c3483bf64d7fbc4e6cacb346270.tar.gz |
Fixed/added doctests
-rw-r--r-- | rsa/common.py | 13 | ||||
-rw-r--r-- | rsa/keygen.py | 13 | ||||
-rw-r--r-- | rsa/transform.py | 12 |
3 files changed, 31 insertions, 7 deletions
diff --git a/rsa/common.py b/rsa/common.py index d00a44d..b8f7aa6 100644 --- a/rsa/common.py +++ b/rsa/common.py @@ -3,7 +3,16 @@ import math def bit_size(number): - """Returns the number of bits required to hold a specific long number""" + '''Returns the number of bits required to hold a specific long number. - return int(math.ceil(math.log(number,2))) + >>> bit_size(1023) + 10 + >>> bit_size(1024) + 10 + >>> bit_size(1025) + 11 + + ''' + + return int(math.ceil(math.log(number, 2))) diff --git a/rsa/keygen.py b/rsa/keygen.py index 7a7cdb6..42601b8 100644 --- a/rsa/keygen.py +++ b/rsa/keygen.py @@ -1,4 +1,13 @@ -'''RSA key generation code.''' +'''RSA key generation code. + +Create new keys with the newkeys() function. + +The private key consists of a dict {d: ...., p: ...., q: ....). + +The public key consists of a dict {e: ..., , n: p*q) + + +''' import rsa.prime @@ -86,7 +95,7 @@ def newkeys(nbits): key consists of a dict {d: ...., p: ...., q: ....). """ - nbits = max(9,nbits) # Don't let nbits go below 9 bits + nbits = max(9, nbits) # Don't let nbits go below 9 bits (p, q, e, d) = gen_keys(nbits) return ( {'e': e, 'n': p*q}, {'d': d, 'p': p, 'q': q} ) diff --git a/rsa/transform.py b/rsa/transform.py index b35f4b7..9cd1ef3 100644 --- a/rsa/transform.py +++ b/rsa/transform.py @@ -19,6 +19,7 @@ def bytes2int(bytes): >>> l = [128, 64, 15] >>> bytes2int(l) #same as bytes2int('\x80@\x0f') 8405007 + """ if not (type(bytes) is types.ListType or type(bytes) is types.StringType): @@ -34,13 +35,14 @@ def bytes2int(bytes): return integer def int2bytes(number): - """Converts a number to a string of bytes. + r'''Converts a number to a string of bytes. - >>>int2bytes(123456789) + >>> int2bytes(123456789) '\x07[\xcd\x15' >>> bytes2int(int2bytes(123456789)) 123456789 - """ + + ''' if not (type(number) is types.LongType or type(number) is types.IntType): raise TypeError("You must pass a long or an int") @@ -60,6 +62,7 @@ def to64(number): >>> to64(10) 'A' + """ if not (type(number) is types.LongType or type(number) is types.IntType): @@ -89,6 +92,7 @@ def from64(number): >>> from64(49) 1 + """ if not (type(number) is types.LongType or type(number) is types.IntType): @@ -118,6 +122,7 @@ def int2str64(number): >>> int2str64(123456789) '7MyqL' + """ if not (type(number) is types.LongType or type(number) is types.IntType): @@ -138,6 +143,7 @@ def str642int(string): >>> str642int('7MyqL') 123456789 + """ if not (type(string) is types.ListType or type(string) is types.StringType): |