Skip to content

Commit

Permalink
Fix mod_sqrt for a = 1, p = 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukundan314 committed Nov 2, 2024
1 parent d6d3efc commit f115dfc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyrival/algebra/mod_sqrt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def mod_sqrt(a, p):
"""returns x s.t. x**2 == a (mod p)"""
a %= p
if a == 0:
return 0
if a < 2:
return a
assert pow(a, (p - 1) // 2, p) == 1
if p & 3 == 3:
return pow(a, (p + 1) // 4, p)
Expand Down

0 comments on commit f115dfc

Please sign in to comment.