summaryrefslogtreecommitdiff
path: root/rsa/__init__.py
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2009-01-23 14:46:06 +0100
committerSybren A. Stüvel <sybren@stuvel.eu>2009-01-23 14:46:06 +0100
commit70d72090e7444a8138f066958a30dcec4df176fa (patch)
treea256b3f4f2719f92906b8fc784adad38f9f97be9 /rsa/__init__.py
parentd37660e006d97de48d673a2b459e5cb4cd10b8d8 (diff)
downloadrsa-git-70d72090e7444a8138f066958a30dcec4df176fa.tar.gz
Fixed a math error when message=0
Diffstat (limited to 'rsa/__init__.py')
-rw-r--r--rsa/__init__.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/rsa/__init__.py b/rsa/__init__.py
index 24b4243..151d777 100644
--- a/rsa/__init__.py
+++ b/rsa/__init__.py
@@ -19,9 +19,6 @@ import sys
import types
import zlib
-def log(x, base = 10):
- return math.log(x) / math.log(base)
-
def gcd(p, q):
"""Returns the greatest common divisor of p and q
@@ -110,7 +107,7 @@ def randint(minvalue, maxvalue):
range = maxvalue - minvalue
# Which is this number of bytes
- rangebytes = ceil(log(range, 2) / 8)
+ rangebytes = ceil(math.log(range, 2) / 8)
# Convert to bits, but make sure it's always at least min_nbits*2
rangebits = max(rangebytes * 8, min_nbits * 2)
@@ -166,8 +163,8 @@ def randomized_primality_testing(n, k):
q = 0.5 # Property of the jacobi_witness function
- # t = int(math.ceil(k / log(1/q, 2)))
- t = ceil(k / log(1/q, 2))
+ # t = int(math.ceil(k / math.log(1/q, 2)))
+ t = ceil(k / math.log(1/q, 2))
for i in range(t+1):
x = randint(1, n-1)
if jacobi_witness(x, n): return False
@@ -324,7 +321,8 @@ def encrypt_int(message, ekey, n):
if not type(message) is types.LongType:
raise TypeError("You must pass a long or an int")
- if math.floor(log(message, 2)) > math.floor(log(n, 2)):
+ if message > 0 and \
+ math.floor(math.log(message, 2)) > math.floor(math.log(n, 2)):
raise OverflowError("The message is too long")
return fast_exponentiation(message, ekey, n)
@@ -367,7 +365,7 @@ def chopstring(message, key, n, funcref):
msglen = len(message)
mbits = msglen * 8
- nbits = int(math.floor(log(n, 2)))
+ nbits = int(math.floor(math.log(n, 2)))
nbytes = nbits / 8
blocks = msglen / nbytes