summaryrefslogtreecommitdiff
path: root/rsa/common.py
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
commit87f8079ff5a601b03301f434603ef9ab045a0794 (patch)
treedd30c6fe94773f64481f0d2d49028b344e364301 /rsa/common.py
parente97d0d730367ad3b49efc712c01509500939c904 (diff)
downloadrsa-git-87f8079ff5a601b03301f434603ef9ab045a0794.tar.gz
Re-implements byte_size using divmod avoiding floating-point calculations.
Diffstat (limited to 'rsa/common.py')
-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):