pycryptodome icon indicating copy to clipboard operation
pycryptodome copied to clipboard

Crypto.Util.number.size is a bit slow

Open jneb opened this issue 4 years ago • 2 comments

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() ?

jneb avatar Nov 24 '20 13:11 jneb

Good point. This size function is a left-over from Python 2.6 and older, which are not supported anymore.

Legrandin avatar Nov 25 '20 22:11 Legrandin

I just made pull request #484 that addresses this issue and does two more improvements.

jneb avatar Nov 30 '20 11:11 jneb

Fixed with a31d1634b0591570fa744559c62232fdce693eec

Legrandin avatar Dec 12 '22 21:12 Legrandin