Skip to content

Crypto.Util.number.size is a bit slow #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jneb opened this issue Nov 24, 2020 · 3 comments
Closed

Crypto.Util.number.size is a bit slow #479

jneb opened this issue Nov 24, 2020 · 3 comments

Comments

@jneb
Copy link

jneb commented Nov 24, 2020

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

@Legrandin
Copy link
Owner

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

@jneb
Copy link
Author

jneb commented Nov 30, 2020

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

@Legrandin
Copy link
Owner

Fixed with a31d163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants