Fixed another bug
This commit is contained in:
parent
4b07a4734b
commit
770330fef4
@ -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);
|
||||
|
@ -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,
|
||||
|
12
prime.php
12
prime.php
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user