Skip to content
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

Py3 #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Py3 #1

wants to merge 4 commits into from

Conversation

laurentbenaroya
Copy link

Thank you for this nice code.
I made some modifications to make the code work with any prime number p. The main idea is that Q = P-1 and that before solving the linear equation denum*x = num % Q, we must first calculate the gcd between denum, num and Q. If this gcd is equal to 1, it is good. Otherwise, solve (denum/thegcd) = (num/thegcd) mod (Q/thegcd) gives res0 and check all solutions of the form res0+k (Q/thegcd), for k in [0, thegcd[.
The code now works with Python 3.
I also use the package gmpy2 for the computation of the modular inverse and the gcd. This package can handle very large integers. If you want to avoid dependencies, you can put the extended Euclid algorithm in another file than pollard_rho.py for more clarity.
Finally, I made some cosmetic changes and added a test.py file with a non safe prime number.

@markusju
Copy link
Owner

Hi Laurent,

thanks very much for your input. Much appreciated. :) Please allow some time for me to review this.

Many thanks,

Markus

@laurentbenaroya
Copy link
Author

laurentbenaroya commented Jul 1, 2024 via email

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

Successfully merging this pull request may close these issues.

3 participants