modular arithmetic course - challenge 6 - résidus quadratique

This commit is contained in:
boyreau 2026-11-14 14:46:20 +01:00
commit 9c960bf2f1
2 changed files with 18 additions and 0 deletions

View file

@ -26,3 +26,18 @@ def extended_gcd(a: int, b: int) -> (int, int, int):
a = b
b = r
return a, u[-2], v[-2]
# Challenge 4 - quadratic residues
def quadratic_residue(N: int, x: int):
"""Find the quadratic residue of x mod N.
Args:
N: a prime integer
x: the integer for which we look for a quadratic residue.
Returns:
Either none or the square root of x mod N.
"""
for i in range(N):
if pow(i, 2, N) == x:
return i
return None