modular arithmetic course - challenge 6 - résidus quadratique
This commit is contained in:
parent
3099b363fa
commit
9c960bf2f1
2 changed files with 18 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue