Updated prime module
This commit is contained in:
parent
3abf9fbed1
commit
6994d614ac
@ -152,10 +152,12 @@ class PrimeModule
|
|||||||
$k = 0;
|
$k = 0;
|
||||||
do {
|
do {
|
||||||
$ys = $y;
|
$ys = $y;
|
||||||
|
$i = 0;
|
||||||
do {
|
do {
|
||||||
|
$i++;
|
||||||
$y = Tools::posmod(Tools::posmod(pow($y, 2), $n) + $c, $n);
|
$y = Tools::posmod(Tools::posmod(pow($y, 2), $n) + $c, $n);
|
||||||
$q = Tools::posmod($q * abs($x - $y), $n);
|
$q = Tools::posmod($q * abs($x - $y), $n);
|
||||||
} while (min($m, $r - $k));
|
} while ($i < min($m, $r - $k));
|
||||||
$g = $this->gcd($q, $n);
|
$g = $this->gcd($q, $n);
|
||||||
$k += $m;
|
$k += $m;
|
||||||
} while ($k < $r and $g == 1);
|
} while ($k < $r and $g == 1);
|
||||||
@ -272,7 +274,7 @@ class PrimeModule
|
|||||||
public function totient($n)
|
public function totient($n)
|
||||||
{
|
{
|
||||||
$totients = [];
|
$totients = [];
|
||||||
if (($n == 0)) {
|
if ($n == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (isset($totients[$n])) {
|
if (isset($totients[$n])) {
|
||||||
@ -289,11 +291,11 @@ class PrimeModule
|
|||||||
|
|
||||||
public function gcd($a, $b)
|
public function gcd($a, $b)
|
||||||
{
|
{
|
||||||
if (($a == $b)) {
|
if ($a == $b) {
|
||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
while (($b > 0)) {
|
while ($b > 0) {
|
||||||
list($a, $b) = [$b, posmod($a, $b)];
|
list($a, $b) = [$b, Tools::posmod($a, $b)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $a;
|
return $a;
|
||||||
|
Loading…
Reference in New Issue
Block a user