def _discrete_log_shanks_steps(n, a, b, order=None):
 a %= n
 b %= n
 if (order is None):
  order = n_order(b, n)
 m = (isqrt(order) + 1)
 T = dict()
 x = 1
 for i in range(m):
  T[x] = i
  x = ((x * b) % n)
 z = mod_inverse(b, n)
 z = pow(z, m, n)
 x = a
 for i in range(m):
  if (x in T):
   return ((i * m) + T[x])
  x = ((x * z) % n)
 raise ValueError('Log does not exist')

def _discrete_log_shanks_steps ( n , a , b , order = None ) : a %= n b %= n if ( order is None ) : order = n_order ( b , n ) m = ( isqrt ( order ) + 1 ) T = dict ( ) x = 1 for i in range ( m ) : T [ x ] = i x = ( ( x * b ) % n ) z = mod_inverse ( b , n ) z = pow ( z , m , n ) x = a for i in range ( m ) : if ( x in T ) : return ( ( i * m ) + T [ x ] ) x = ( ( x * z ) % n ) raise ValueError ( 'Log does not exist' )
baby-step giant-step algorithm for computing the discrete logarithm of a to the base b modulo n .