diff options
Diffstat (limited to 'rsa/common.py')
-rw-r--r-- | rsa/common.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/rsa/common.py b/rsa/common.py index b8f7aa6..7c852b6 100644 --- a/rsa/common.py +++ b/rsa/common.py @@ -14,5 +14,18 @@ def bit_size(number): ''' + if number < 0: + raise ValueError('Only nonnegative numbers possible: %s' % number) + + if number == 0: + return 1 + return int(math.ceil(math.log(number, 2))) +def byte_size(number): + """Returns the number of bytes required to hold a specific long number. + + The number of bytes is rounded up. + """ + + return int(math.ceil(bit_size(number) / 8.0)) |