Quadratic Residue
- https://cryptohack.org/courses/modular/root1/
Basic
An integer x
is called a quadratic residue modulo p
.
Brute Force
To calculate a quadratic residue, the following Python script is an example for that.
Legendre Symbol
According to Legendre Symbol, the following rules hold:
# `a` is a quadratic residue and `a != 0 mod p`
a**(p-1)/2 mod p == 1
# `a` is a quadratic non-residue mod p
a**(p-1)/2 mod p == -1
# `a ≡ 0 mod p`
a**(p-1)/2 mod p == 0
We can check if an integer is a quadratic residue or not referring to the above.