def repSqAlg(g, x):
	y = g
	z = 1
	x_bckw = bin(x)[2::][::-1]
	print "g = " + str(g)
	print "x = " + x_bckw

	for i in range(0, len(x_bckw)):
		if(x_bckw[i] == '1'):
			z = z*y
		y = pow(y,2)
		print "y = " + str(y) + " z = " + str(z)

	return z

print "5^53 = " + str(repSqAlg(5,53))

ca8ce4d3b0bcc5ce8d44a1b7a8dfdc61fdf55919
def repSqAlg(g, x):
	y = g
	z = 1
	x_bckw = bin(x)[2::][::-1]
	print "g = " + str(g)
	print "x = " + x_bckw

	for i in range(0, len(x_bckw)):
		if(x_bckw[i] == '1'):
			z = z*y
		y = pow(y,2)
		print "y = " + str(y) + " z = " + str(z)

	return z

print "5^53 = " + str(repSqAlg(5,53))
