Fixed another bug
This commit is contained in:
parent
4b07a4734b
commit
770330fef4
|
@ -231,8 +231,7 @@ class Session
|
||||||
pyjslib_printnl('Requesting pq');
|
pyjslib_printnl('Requesting pq');
|
||||||
$ResPQ = $this->method_call('req_pq', ['nonce' => $nonce]);
|
$ResPQ = $this->method_call('req_pq', ['nonce' => $nonce]);
|
||||||
$server_nonce = $ResPQ['server_nonce'];
|
$server_nonce = $ResPQ['server_nonce'];
|
||||||
$public_key_fingerprint = $ResPQ['server_public_key_fingerprints'][0];
|
$public_key_fingerprint = (int)$ResPQ['server_public_key_fingerprints'][0];
|
||||||
var_dump($public_key_fingerprint);
|
|
||||||
$pq_bytes = $ResPQ['pq'];
|
$pq_bytes = $ResPQ['pq'];
|
||||||
|
|
||||||
$pq = new \phpseclib\Math\BigInteger($pq_bytes, 256);
|
$pq = new \phpseclib\Math\BigInteger($pq_bytes, 256);
|
||||||
|
@ -244,8 +243,8 @@ class Session
|
||||||
}
|
}
|
||||||
assert(($pq->equals($p->multiply($q))) && ($p < $q));
|
assert(($pq->equals($p->multiply($q))) && ($p < $q));
|
||||||
pyjslib_printnl(sprintf('Factorization %s = %s * %s', $pq, $p, $q));
|
pyjslib_printnl(sprintf('Factorization %s = %s * %s', $pq, $p, $q));
|
||||||
$p_bytes = $this->struct->pack('>Q', (string) $p);
|
$p_bytes = $this->struct->pack('>I', (string) $p);
|
||||||
$q_bytes = $this->struct->pack('>Q', (string) $q);
|
$q_bytes = $this->struct->pack('>I', (string) $q);
|
||||||
$f = file_get_contents(__DIR__.'/rsa.pub');
|
$f = file_get_contents(__DIR__.'/rsa.pub');
|
||||||
$key = new \phpseclib\Crypt\RSA();
|
$key = new \phpseclib\Crypt\RSA();
|
||||||
$key->load($f);
|
$key->load($f);
|
||||||
|
|
|
@ -166,12 +166,13 @@ class Session:
|
||||||
nonce=nonce,
|
nonce=nonce,
|
||||||
server_nonce=server_nonce,
|
server_nonce=server_nonce,
|
||||||
new_nonce=new_nonce)
|
new_nonce=new_nonce)
|
||||||
|
print(len(data), len(p_bytes))
|
||||||
sha_digest = SHA.new(data).digest()
|
sha_digest = SHA.new(data).digest()
|
||||||
random_bytes = os.urandom(255-len(data)-len(sha_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
|
to_encrypt = sha_digest + data + random_bytes
|
||||||
encrypted_data = key.encrypt(to_encrypt, 0)[0]
|
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',
|
server_dh_params = self.method_call('req_DH_params',
|
||||||
nonce=nonce,
|
nonce=nonce,
|
||||||
server_nonce=server_nonce,
|
server_nonce=server_nonce,
|
||||||
|
|
12
prime.php
12
prime.php
|
@ -177,11 +177,13 @@ class PrimeModule
|
||||||
public function primefactors($pq, $sort = false)
|
public function primefactors($pq, $sort = false)
|
||||||
{
|
{
|
||||||
if (function_exists('shell_exec')) {
|
if (function_exists('shell_exec')) {
|
||||||
// Use the python version.
|
try {
|
||||||
$res = explode(' ', shell_exec('python getpq.py '.$pq));
|
// Use the python version.
|
||||||
if (count($res) == 2) {
|
$res = explode(' ', shell_exec('python getpq.py '.$pq));
|
||||||
return $res;
|
if (count($res) == 2) {
|
||||||
}
|
return $res;
|
||||||
|
}
|
||||||
|
} catch (ErrorException $e) { ; };
|
||||||
}
|
}
|
||||||
// Else do factorization with wolfram alpha :)))))
|
// Else do factorization with wolfram alpha :)))))
|
||||||
$query = 'Do prime factorization of '.$pq;
|
$query = 'Do prime factorization of '.$pq;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user