summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-11 02:41:08 +0530
committerYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-11 02:41:08 +0530
commitfbaec865aea759244fa8a3d3ef2064992a679334 (patch)
treedd30c6fe94773f64481f0d2d49028b344e364301
parent2eeea2ca19fdea9f354bbec685e168fee370d19f (diff)
downloadrsa-fbaec865aea759244fa8a3d3ef2064992a679334.tar.gz
Re-implements byte_size using divmod avoiding floating-point calculations.
-rw-r--r--rsa/common.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/rsa/common.py b/rsa/common.py
index 4d7698f..33714a6 100644
--- a/rsa/common.py
+++ b/rsa/common.py
@@ -17,7 +17,6 @@
'''Common functionality shared by several modules.'''
-import math
def bit_size(number):
'''Returns the number of bits required to hold a specific long number.
@@ -67,7 +66,13 @@ def byte_size(number):
129
"""
- return int(math.ceil(bit_size(number) / 8.0))
+ # Does not perform floating-point division and uses built-in divmod
+ # operator.
+ quanta, mod = divmod(bit_size(number), 8)
+ if mod:
+ quanta += 1
+ return quanta
+ #return int(math.ceil(bit_size(number) / 8.0))
def extended_gcd(a, b):