Skip to content
This repository was archived by the owner on Apr 20, 2025. It is now read-only.

Commit 87f8079

Browse files
committed
Re-implements byte_size using divmod avoiding floating-point calculations.
1 parent e97d0d7 commit 87f8079

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

rsa/common.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
'''Common functionality shared by several modules.'''
1818

1919

20-
import math
2120

2221
def bit_size(number):
2322
'''Returns the number of bits required to hold a specific long number.
@@ -67,7 +66,13 @@ def byte_size(number):
6766
129
6867
"""
6968

70-
return int(math.ceil(bit_size(number) / 8.0))
69+
# Does not perform floating-point division and uses built-in divmod
70+
# operator.
71+
quanta, mod = divmod(bit_size(number), 8)
72+
if mod:
73+
quanta += 1
74+
return quanta
75+
#return int(math.ceil(bit_size(number) / 8.0))
7176

7277

7378
def extended_gcd(a, b):

0 commit comments

Comments
 (0)