mod the input

This commit is contained in:
filifa 2025-12-11 23:49:34 -05:00
parent 3f7519bed4
commit f38c0f5063
1 changed files with 5 additions and 0 deletions

View File

@ -165,6 +165,11 @@ function modsqrt(n, modulus) {
// TODO: add special case for modulus = 3 (mod 4)
n %= modulus;
if (n < 0n) {
n += modulus;
}
if (n % modulus === 0n) {
return 0n;
} else if (legendreSymbol(n, modulus) !== 1n) {