Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created November 11, 2016 15:43
Show Gist options
  • Save AndyNovo/d38cd845725cdf18f7d327067a4b0a70 to your computer and use it in GitHub Desktop.
Save AndyNovo/d38cd845725cdf18f7d327067a4b0a70 to your computer and use it in GitHub Desktop.
factors = (p-1).factor()
remainders = []
bases = []
for factor in factors:
p_i = factor[0]**factor[1]
LHS = pow(e, int((p-1)/p_i), p)
RHBase = pow(g, int((p-1)/p_i), p)
if RHBase == 1:
print "multiple"
for r_i in range(p_i):
if pow(RHBase, r_i, p) == LHS:
remainders.append(r_i)
bases.append(p_i)
break
x_guess = crt(remainders, bases)
print x_guess, pow(g, x_guess, p) == e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment