def DLPpow2(u, g, n):
if n == 1:
return 0 if u == 1 else 1
a = n // 2
b = n - a
c = DLPpow2(u**(2**b), g**(2**b), a)
d = DLPpow2(u*g**(2**a-c),g**(2**a), b)
return c + (d - 1) % 2**b
def sqrt(x, q):
if x == 0:
return 0
m = q - 1
while m % 2 == 0:
m //= 2
v = x ** ((m - 1) // 2)
w = x * v
u = w * v
e = DLPpow2(u, g, n)
return None if e % 2 == 1 else w * g**((2**n - e) // 2)
q = 5**3
r = sqrt(13, q)
print(r)
print(r**2 % q)
To embed this project on your website, copy the following code and paste it into your website's HTML: