1111
1212from __future__ import division
1313
14+ import sys
1415from six import integer_types , PY2
1516from six .moves import reduce
1617
@@ -219,7 +220,7 @@ def square_root_mod_prime(a, p):
219220 raise RuntimeError ("No b found." )
220221
221222
222- if GMPY2 :
223+ if GMPY2 : # pragma: no branch
223224
224225 def inverse_mod (a , m ):
225226 """Inverse of a mod m."""
@@ -228,14 +229,14 @@ def inverse_mod(a, m):
228229 return powmod (a , - 1 , m )
229230
230231
231- elif GMPY :
232+ elif GMPY : # pragma: no branch
232233
233234 def inverse_mod (a , m ):
234235 """Inverse of a mod m."""
235- # while libgmp likely does support inverses modulo, it is accessible
236- # only using the native `pow()` function, and `pow()` sanity checks
237- # the parameters before passing them on to underlying implementation
238- # on Python2
236+ # while libgmp does support inverses modulo, it is accessible
237+ # only using the native `pow()` function, and `pow()` in gmpy sanity
238+ # checks the parameters before passing them on to underlying
239+ # implementation
239240 if a == 0 :
240241 return 0
241242 a = mpz (a )
@@ -250,7 +251,16 @@ def inverse_mod(a, m):
250251 return lm % m
251252
252253
253- else :
254+ elif sys .version_info >= (3 , 8 ): # pragma: no branch
255+
256+ def inverse_mod (a , m ):
257+ """Inverse of a mod m."""
258+ if a == 0 :
259+ return 0
260+ return pow (a , - 1 , m )
261+
262+
263+ else : # pragma: no branch
254264
255265 def inverse_mod (a , m ):
256266 """Inverse of a mod m."""
0 commit comments