-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
89 lines (76 loc) · 3.44 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib/phpseclib');
include('Math/BigInteger.php');
include('Crypt/RSA.php');
include('PHP/Compat/Function/str_split.php');
include('PHP/Compat/Function/bcpowmod.php');
error_reporting(E_ALL);
echo 'PHP Version: ' . phpversion() . "\n";
echo 'xdebug is ';
if (!extension_loaded('xdebug')) {
echo 'not ';
}
echo "loaded\n";
echo defined('PHP_INT_SIZE') ? PHP_INT_SIZE : 4;
echo "\n";
if (function_exists('opcache_get_status') && ($status = opcache_get_status())) {
echo $status['jit']['enabled'] && $status['jit']['on'] ?
'JIT is enabled' :
'JIT is not enabled';
} else {
echo 'JIT is not enabled';
}
echo "\n";
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL);
define('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
for ($i = 1; $i <= 3; $i++) {
$start = microtime_float();
$rsa = new Crypt_RSA();
$plaintext = 'hello, world!';
$rsa->loadKey('-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAylq1ZRSREX7DWHUKg4HX
KGN5C8GQgasXaobkF0J5ok/TfDQnG4WntB/brjQaQRN9phFovHEClj2XywYfL/s9
syHHioaVOIMZ86cLP7xzJc6dF/bydPLD1p14DkpJLgCSx6CyTlFzOhmm4/YMEh4t
XR8FHY1f3pgWwEDXkkMKo/2U5FIIH0HBf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iOY68YZX
LwwqXa9Rc1uCUDKXHLGMPGAgZTfb6z19EAsGG08LQbeClZM0Jm1c83skqN8mnbrn
nPSiFc09hSHRLmul195xOkpb0IxZ+8oeljXnbz6IJagzHLP40lvHx/rrAoGBANYu
bwjrRDDWnaQQbPY3Z9fTHx9AD2ErPyVsg+OGvUqDGtTU/32kYR4anUkNaldLcI3k
/QtYgxwE0zcCn9+fmfwYXvIEfmJG1+NH6Mw0rLt15qO6vhZ/fx6ewV0ZtTUvxj2X
yGO5gXE26v3Il+KtlIXm3DBFR5/3+wQIbtaT03GxAoGBAN8dtJoc0j4pANznVQyf
sNvkNcIDcpKD2ZoX4slAOxxxMBj7HR1pxev6FSyK/djX8PWKcxzSmkuu9tC93ld9
zFPvETgs0TXhj+wYuq4+hhn+ao5YyD7INQFzmJsZ+nuExcbmWapJV5WK92rSA7Wj
27vkQLo1zE9Kv1rC2gNy2+d7AoGBAInpFjfg/WSRHKpipTaZEHVpDNYbcou3xA49
5GKiBMqwxpsal3R4Xsx6iKJcUAfrnIrRUpp2oN1uwe3e88CTTRyFOMWPXS28vhAr
4lty43JFhYARo4prCBhYUtu2zPZ1T6mjTTXhYdbbbM6C1kHwUP0zXL58LZV0oJ3F
LFFgmDrRAoGAS9i9FLcipuff0n+1e83rRiE78rAYqA345Y5exakEqfW/orTDfYcq
or0jV1Oh8ZpspoQCEgei9pmP8BoN3j4JCV6sOduXPsRQfIqV7zAFCcIEqxnG1Xhz
vnGFhUKyff8ObWammbWnYnnzXnXRCL+982W8LoOhTzTv7LuSIMq3eOg=
-----END RSA PRIVATE KEY-----'); // private key
$result = $rsa->decrypt($ciphertext);
$elapsed = microtime_float() - $start;
echo "trial#$i: $elapsed seconds ($result)\n";
}