def _discrete_log_trial_mul(n, a, b, order=None):
 a %= n
 b %= n
 if (order is None):
  order = n
 x = 1
 k = 1
 for i in range(order):
  if (x == a):
   return i
  x = ((x * b) % n)
 raise ValueError('Log does not exist')

def _discrete_log_trial_mul ( n , a , b , order = None ) : a %= n b %= n if ( order is None ) : order = n x = 1 k = 1 for i in range ( order ) : if ( x == a ) : return i x = ( ( x * b ) % n ) raise ValueError ( 'Log does not exist' )
trial multiplication algorithm for computing the discrete logarithm of a to the base b modulo n .