Updating PrimeModuleg
This commit is contained in:
parent
8ddc8237e5
commit
270a8acec1
@ -224,27 +224,24 @@ class PrimeModule
|
|||||||
|
|
||||||
|
|
||||||
$factors = [];
|
$factors = [];
|
||||||
$one = new \phpseclib\Math\BigInteger(1);
|
$limit = sqrt($n) + 1;
|
||||||
$two = new \phpseclib\Math\BigInteger(2);
|
|
||||||
$limit = $n->root()->add($one);
|
|
||||||
foreach ($this->smallprimes as $checker) {
|
foreach ($this->smallprimes as $checker) {
|
||||||
$checker = new \phpseclib\Math\BigInteger($checker);
|
if ($checker > $limit) {
|
||||||
if ($limit->compare($checker) == -1) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while ($n->modPow($one, $checker)->toString() == '0') {
|
do {
|
||||||
$factors[] = $checker;
|
$factors[] = $checker;
|
||||||
$n = $n->divide($checker)[0];
|
$n = intval($n / $checker);
|
||||||
$limit = $n->root()->add($one);
|
$limit = sqrt($n) + 1;
|
||||||
if ($limit->compare($checker) == -1) {
|
if ($checker > $limit) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (Tools::posmod($n, $checker) == 0);
|
||||||
}
|
}
|
||||||
if ($n->compare($two) == -1) {
|
if ($n < 2) {
|
||||||
return $factors;
|
return $factors;
|
||||||
}
|
}
|
||||||
while ($n->compare($two) == 1) {
|
while ($n > 1) {
|
||||||
if ($n->isprime()) {
|
if ($n->isprime()) {
|
||||||
$factors[] = $n;
|
$factors[] = $n;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user