pycryptodome
pycryptodome copied to clipboard
Crypto.Util.number.size is a bit slow
I saw that the code for Crypto.Util.number.size is:
def size (N):
"""Returns the size of the number N in bits."""
bits = 0
while N >> bits:
bits += 1
return bits
How about:
return N.bit_length()
?
Good point. This size
function is a left-over from Python 2.6 and older, which are not supported anymore.
I just made pull request #484 that addresses this issue and does two more improvements.
Fixed with a31d1634b0591570fa744559c62232fdce693eec