Berry Schoenmakers <[email protected]> added the comment:
In pure Python this seems to be the better option to compute inverses:
def modinv(a, m): # assuming m > 0
b = m
s, s1 = 1, 0
while b:
a, (q, b) = b, divmod(a, b)
s, s1 = s1, s - q * s1
if a != 1:
raise ValueError('inverse does not exist')
return s if s >= 0 else s + m
Binary xgcd algorithms coded in pure Python run much slower.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36027>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com