Fixed another bug

This commit is contained in:
Daniil Gentili 2016-08-06 02:49:38 +02:00
parent 4b07a4734b
commit 770330fef4
3 changed files with 13 additions and 11 deletions

View File

@ -231,8 +231,7 @@ class Session
pyjslib_printnl('Requesting pq');
$ResPQ = $this->method_call('req_pq', ['nonce' => $nonce]);
$server_nonce = $ResPQ['server_nonce'];
$public_key_fingerprint = $ResPQ['server_public_key_fingerprints'][0];
var_dump($public_key_fingerprint);
$public_key_fingerprint = (int)$ResPQ['server_public_key_fingerprints'][0];
$pq_bytes = $ResPQ['pq'];
$pq = new \phpseclib\Math\BigInteger($pq_bytes, 256);
@ -244,8 +243,8 @@ class Session
}
assert(($pq->equals($p->multiply($q))) && ($p < $q));
pyjslib_printnl(sprintf('Factorization %s = %s * %s', $pq, $p, $q));
$p_bytes = $this->struct->pack('>Q', (string) $p);
$q_bytes = $this->struct->pack('>Q', (string) $q);
$p_bytes = $this->struct->pack('>I', (string) $p);
$q_bytes = $this->struct->pack('>I', (string) $q);
$f = file_get_contents(__DIR__.'/rsa.pub');
$key = new \phpseclib\Crypt\RSA();
$key->load($f);

View File

@ -166,12 +166,13 @@ class Session:
nonce=nonce,
server_nonce=server_nonce,
new_nonce=new_nonce)
print(len(data), len(p_bytes))
sha_digest = SHA.new(data).digest()
random_bytes = os.urandom(255-len(data)-len(sha_digest))
print(len(sha_digest), len(data), len(random_bytes))
to_encrypt = sha_digest + data + random_bytes
encrypted_data = key.encrypt(to_encrypt, 0)[0]
print("Starting Diffie Hellman key exchange")
print("Starting Diffie Hellman key exchange", len(to_encrypt))
server_dh_params = self.method_call('req_DH_params',
nonce=nonce,
server_nonce=server_nonce,

View File

@ -177,11 +177,13 @@ class PrimeModule
public function primefactors($pq, $sort = false)
{
if (function_exists('shell_exec')) {
// Use the python version.
$res = explode(' ', shell_exec('python getpq.py '.$pq));
if (count($res) == 2) {
return $res;
}
try {
// Use the python version.
$res = explode(' ', shell_exec('python getpq.py '.$pq));
if (count($res) == 2) {
return $res;
}
} catch (ErrorException $e) { ; };
}
// Else do factorization with wolfram alpha :)))))
$query = 'Do prime factorization of '.$pq;