Applied fixes from StyleCI
This commit is contained in:
parent
5c0dae2782
commit
7d439bcbcb
@ -19,6 +19,7 @@ function newcrc32($data)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to dump the hex version of a string.
|
* Function to dump the hex version of a string.
|
||||||
|
*
|
||||||
* @param $what What to dump.
|
* @param $what What to dump.
|
||||||
*/
|
*/
|
||||||
function hex_dump(...$what)
|
function hex_dump(...$what)
|
||||||
|
19
prime.php
19
prime.php
@ -72,8 +72,10 @@ class PrimeModule
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// taken from https://github.com/enricostara/telegram-mt-node/blob/master/lib/security/pq-finder.js
|
// taken from https://github.com/enricostara/telegram-mt-node/blob/master/lib/security/pq-finder.js
|
||||||
public function getpq($pq) {
|
public function getpq($pq)
|
||||||
|
{
|
||||||
$zero = new \phpseclib\Math\BigInteger(0);
|
$zero = new \phpseclib\Math\BigInteger(0);
|
||||||
$one = new \phpseclib\Math\BigInteger(1);
|
$one = new \phpseclib\Math\BigInteger(1);
|
||||||
$two = new \phpseclib\Math\BigInteger(2);
|
$two = new \phpseclib\Math\BigInteger(2);
|
||||||
@ -81,7 +83,7 @@ class PrimeModule
|
|||||||
|
|
||||||
$p = new \phpseclib\Math\BigInteger();
|
$p = new \phpseclib\Math\BigInteger();
|
||||||
$q = new \phpseclib\Math\BigInteger();
|
$q = new \phpseclib\Math\BigInteger();
|
||||||
while (!$pq->equals($p->multiply($q))) {
|
while (!$pq->equals($p->multiply($q))) {
|
||||||
for ($i = 0; $i < 3; $i++) {
|
for ($i = 0; $i < 3; $i++) {
|
||||||
$q = new \phpseclib\Math\BigInteger((random_int(0, 128) & 15) + 17);
|
$q = new \phpseclib\Math\BigInteger((random_int(0, 128) & 15) + 17);
|
||||||
$x = new \phpseclib\Math\BigInteger(random_int(0, 1000000000) + 1);
|
$x = new \phpseclib\Math\BigInteger(random_int(0, 1000000000) + 1);
|
||||||
@ -93,10 +95,10 @@ class PrimeModule
|
|||||||
$c = $q;
|
$c = $q;
|
||||||
while (!$b->equals($zero)) {
|
while (!$b->equals($zero)) {
|
||||||
if ($b->powMod($one, $two)->equals($zero)) {
|
if ($b->powMod($one, $two)->equals($zero)) {
|
||||||
$c = $c->add($a);
|
$c = $c->add($a);
|
||||||
if ($c->compare($pq) > 0) {
|
if ($c->compare($pq) > 0) {
|
||||||
$c = $c->subtract($pq);
|
$c = $c->subtract($pq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$a = $a->add($a);
|
$a = $a->add($a);
|
||||||
if ($a->compare($pq) > 0) {
|
if ($a->compare($pq) > 0) {
|
||||||
@ -108,7 +110,7 @@ class PrimeModule
|
|||||||
$z = ($y->compare($x) > 0) ? $y->subtract($x) : $x->subtract($y);
|
$z = ($y->compare($x) > 0) ? $y->subtract($x) : $x->subtract($y);
|
||||||
$p = $z->gcd($pq);
|
$p = $z->gcd($pq);
|
||||||
if (!$p->equals($one)) {
|
if (!$p->equals($one)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (($j & ($j - 1)) === 0) {
|
if (($j & ($j - 1)) === 0) {
|
||||||
$y = $x;
|
$y = $x;
|
||||||
@ -121,8 +123,10 @@ class PrimeModule
|
|||||||
$q = $pq->divide(prime)[0];
|
$q = $pq->divide(prime)[0];
|
||||||
}
|
}
|
||||||
$_pq = ($q->compare($p) > 0) ? [$p, $q] : [$q, $p];
|
$_pq = ($q->compare($p) > 0) ? [$p, $q] : [$q, $p];
|
||||||
|
|
||||||
return $_pq;
|
return $_pq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pollard_brent($n)
|
public function pollard_brent($n)
|
||||||
{
|
{
|
||||||
$zero = new \phpseclib\Math\BigInteger(0);
|
$zero = new \phpseclib\Math\BigInteger(0);
|
||||||
@ -179,7 +183,7 @@ class PrimeModule
|
|||||||
{
|
{
|
||||||
$factors = [];
|
$factors = [];
|
||||||
$n = new \phpseclib\Math\BigInteger(1724114033281923457);
|
$n = new \phpseclib\Math\BigInteger(1724114033281923457);
|
||||||
var_dump($this->getpq($n));
|
var_dump($this->getpq($n));
|
||||||
$one = new \phpseclib\Math\BigInteger(1);
|
$one = new \phpseclib\Math\BigInteger(1);
|
||||||
$two = new \phpseclib\Math\BigInteger(2);
|
$two = new \phpseclib\Math\BigInteger(2);
|
||||||
$limit = $n->root()->add($one);
|
$limit = $n->root()->add($one);
|
||||||
@ -264,5 +268,4 @@ var_dump($this->getpq($n));
|
|||||||
{
|
{
|
||||||
return floor(abs(($a * $b)) / $this->gcd($a, $b));
|
return floor(abs(($a * $b)) / $this->gcd($a, $b));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user