Skip to content

Commit

Permalink
test: Use python3.8 pow()
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Apr 21, 2023
1 parent 88881cf commit fa6eb65
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions test/functional/test_framework/util.py
Expand Up @@ -542,18 +542,7 @@ def modinv(a, n):
"""Compute the modular inverse of a modulo n using the extended Euclidean
Algorithm. See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Modular_integers.
"""
# TODO: Change to pow(a, -1, n) available in Python 3.8
t1, t2 = 0, 1
r1, r2 = n, a
while r2 != 0:
q = r1 // r2
t1, t2 = t2, t1 - q * t2
r1, r2 = r2, r1 - q * r2
if r1 > 1:
return None
if t1 < 0:
t1 += n
return t1
return pow(a, -1, n)

class TestFrameworkUtil(unittest.TestCase):
def test_modinv(self):
Expand Down

0 comments on commit fa6eb65

Please sign in to comment.