refactor common logic
This commit is contained in:
parent
f8930cfb4f
commit
e55b3c89b0
|
|
@ -53,14 +53,19 @@ function modpow(base, exponent, modulus) {
|
|||
return result;
|
||||
}
|
||||
|
||||
function witness(a, n) {
|
||||
let d = n - 1n;
|
||||
function factorTwos(n) {
|
||||
let s = 0;
|
||||
while (d % 2n === 0n) {
|
||||
d /= 2n;
|
||||
while (n % 2n === 0n) {
|
||||
n /= 2n;
|
||||
s++;
|
||||
}
|
||||
|
||||
return [n, s];
|
||||
}
|
||||
|
||||
function witness(a, n) {
|
||||
const [d, s] = factorTwos(n - 1n);
|
||||
|
||||
let x = modpow(a, d, n);
|
||||
let y = null;
|
||||
for (let i = 0; i < s; i++) {
|
||||
|
|
@ -106,13 +111,7 @@ function quadraticNonResidue(p) {
|
|||
}
|
||||
|
||||
function tonelliShanks(n, p) {
|
||||
let q = p - 1n;
|
||||
let s = 0;
|
||||
while (q % 2n === 0n) {
|
||||
q /= 2n;
|
||||
s++;
|
||||
}
|
||||
|
||||
const [q, s] = factorTwos(p - 1n);
|
||||
const z = quadraticNonResidue(p);
|
||||
|
||||
let m = s;
|
||||
|
|
|
|||
Loading…
Reference in New Issue