1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 08:54:44 +01:00
This commit is contained in:
danogentili 2016-07-18 18:56:33 +02:00
parent fced0ddc0f
commit fe2078f566
4 changed files with 11 additions and 9 deletions

View File

@ -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];

View File

@ -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)

View File

@ -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));
}
}

View File

@ -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