diff --git a/mtproto.php b/mtproto.php index 9f6f8dd42..6ec03aa35 100755 --- a/mtproto.php +++ b/mtproto.php @@ -274,7 +274,9 @@ class Session $public_key_fingerprint = $ResPQ['server_public_key_fingerprints'][0]; $pq_bytes = $ResPQ['pq']; $pq = bytes_to_long($pq_bytes); - var_dump($this->PrimeModule->primefactors($pq)); + var_dump($this->PrimeModule->pollard_brent(2118588165281151121)); + + var_dump($this->PrimeModule->primefactors(2118588165281151121));die; list($p, $q) = $this->PrimeModule->primefactors($pq); if ($p > $q) { list($p, $q) = [$q, $p]; diff --git a/mtproto.py b/mtproto.py index 0d8f26b03..c93efd602 100644 --- a/mtproto.py +++ b/mtproto.py @@ -146,6 +146,7 @@ class Session: pq_bytes = ResPQ['pq'] pq = bytes_to_long(pq_bytes) + print(prime.pollard_brent(2118588165281151121)) print(prime.primefactors(2118588165281151121)) exit() [p, q] = prime.primefactors(pq) diff --git a/prime.php b/prime.php index 4f2d51c99..e4f90c6db 100644 --- a/prime.php +++ b/prime.php @@ -12,7 +12,7 @@ class PrimeModule { $res = []; for ($i = 2; $i <= $N; $i++) { - if($i % 2 != 1) continue; + if($i % 2 != 1 && $i != 2) continue; $d = 3; $x = sqrt($i); while ($i % $d != 0 && $d < $x) $d += 2; @@ -68,24 +68,24 @@ class PrimeModule { while (($g == 1)) { $x = $y; foreach (pyjslib_range($r) as $i) { - $y = ((pow($y, 2, $n) + $c) % $n); + $y = ((posmod(pow($y, 2), $n) + $c) % $n); } $k = 0; while (($k < $r) && ($g == 1)) { $ys = $y; foreach (pyjslib_range(min($m, ($r - $k))) as $i) { - $y = ((pow($y, 2, $n) + $c) % $n); + $y = ((posmod(pow($y, 2), $n) + $c) % $n); $q = (($q * abs(($x - $y))) % $n); } - $g = gcd($q, $n); + $g = $this->gcd($q, $n); $k += $m; } $r *= 2; } if (($g == $n)) { while (true) { - $ys = ((pow($ys, 2, $n) + $c) % $n); - $g = gcd(abs(($x - $ys)), $n); + $ys = ((posmod(pow($ys, 2), $n) + $c) % $n); + $g = $this->gcd(abs(($x - $ys)), $n); if (($g > 1)) { break; } @@ -172,7 +172,7 @@ class PrimeModule { } function lcm($a, $b) { - return floor(abs(($a * $b)) / gcd($a, $b)); + return floor(abs(($a * $b)) / $this->gcd($a, $b)); } } \ No newline at end of file diff --git a/prime.py b/prime.py index 051179f61..cd44bd80f 100644 --- a/prime.py +++ b/prime.py @@ -97,7 +97,6 @@ def primefactors(n, sort=False): if isprime(n): factors.append(n) break - print(pollard_brent(n)) factor = pollard_brent(n) # trial division did not fully factor, switch to pollard-brent factors.extend(primefactors(factor)) # recurse to factor the not necessarily prime factor returned by pollard-brent n //= factor