This commit is contained in:
Henry Jen 2020-04-14 23:11:49 +00:00
commit 0278846eaa
91 changed files with 1073 additions and 416 deletions

View file

@ -2178,8 +2178,8 @@ class MutableBigInteger {
}
/**
* Calculate the multiplicative inverse of this mod mod, where mod is odd.
* This and mod are not changed by the calculation.
* Calculate the multiplicative inverse of this modulo mod, where the mod
* argument is odd. This and mod are not changed by the calculation.
*
* This method implements an algorithm due to Richard Schroeppel, that uses
* the same intermediate representation as Montgomery Reduction
@ -2233,8 +2233,18 @@ class MutableBigInteger {
k += trailingZeros;
}
while (c.sign < 0)
c.signedAdd(p);
if (c.compare(p) >= 0) { // c has a larger magnitude than p
MutableBigInteger remainder = c.divide(p,
new MutableBigInteger());
// The previous line ignores the sign so we copy the data back
// into c which will restore the sign as needed (and converts
// it back to a SignedMutableBigInteger)
c.copyValue(remainder);
}
if (c.sign < 0) {
c.signedAdd(p);
}
return fixup(c, p, k);
}
@ -2272,8 +2282,8 @@ class MutableBigInteger {
}
// In theory, c may be greater than p at this point (Very rare!)
while (c.compare(p) >= 0)
c.subtract(p);
if (c.compare(p) >= 0)
c = c.divide(p, new MutableBigInteger());
return c;
}