Cipolla's algorithm: Difference between revisions

m
→‎{{header|Sage}}: Changed - to +, also a few efficiency updates for dealing with large numbers
m (→‎{{header|Sage}}: Fixed a few stray bugs and updated algorithm for cases where p is not prime.)
m (→‎{{header|Sage}}: Changed - to +, also a few efficiency updates for dealing with large numbers)
Line 827:
return ((x1*x2 + y1*y2*u) % p), ((x1*y2 + x2*y1) % p)
 
def cipollaAlgorithm(an, p):
a = powMod(a, 1n, p)
out = []
 
Line 856:
 
if pow(p, 1, 4) == 3:
temp = pow(a, int((p-+1)/4), p)
return [temp, p - temp]
 
 
t = randrange(2, p)
Line 870 ⟶ 871:
x, y = cipollaMult(x, y, x0, y0, u, p)
 
out.extend([x, pow(p -x, 1, p)x])
 
return sorted(out)