This repository has been archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.php
76 lines (62 loc) · 2.33 KB
/
controller.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
<?php
require_once 'Crypt_mcrypt.php';
require_once 'Crypt_openssl.php';
if (!empty($_POST["hash"])) {
$hash = $_POST["hash"];
echo "Hash = <b>{$hash}</b>";
$crypt_mcrypt = new CryptMcrypt($hash);
$crypt_openssl = new CryptOpenssl($hash);
if (!empty($_POST["data"])) {
$data = $_POST["data"];
echo "<br/>Data = <b>{$data}</b>";
echo "<br/>Option Selected = <b>{$_POST["option"]}</b><br/>";
if ($_POST["option"] == "encrypt") {
//using mcrypt
$start_time = microtime(true);
$result = $crypt_mcrypt->Encrypt($data);
$stop_time = microtime(true);
$time_mcrypt = $stop_time - $start_time;
//using openssl
$start_time = microtime(true);
$result = $crypt_openssl->Encrypt($data);
$stop_time = microtime(true);
$time_openssl = $stop_time - $start_time;
CheckResult($result);
echo "<br/>Encrypted data = <b>{$result}</b>";
ShotTime($time_mcrypt,$time_openssl);
// $test_result = $crypt_openssl->Decrypt($result);
// echo "<br/>Test Result = <b>{$test_result}</b>";
}
if ($_POST["option"] == "decrypt") {
//using mcrypt
$start_time = microtime(true);
$result = $crypt_mcrypt->Decrypt($data);
$stop_time = microtime(true);
$time_mcrypt = $stop_time - $start_time;
//using openssl
$result = $crypt_openssl->Decrypt($data);
$stop_time = microtime(true);
$time_openssl = $stop_time - $start_time;
CheckResult($result);
$start_time = microtime(true);
echo "<br/>Decrypted data = <b>{$result}</b>";
ShotTime($time_mcrypt,$time_openssl);
// $test_result = $crypt_openssl->Encrypt($result);
// echo "<br/>Test Result = <b>{$test_result}</b>";
}
} else {
throw new Exception("{{ Data missing }}");
}
} else {
throw new Exception("{{ Hash missing }}");
}
function CheckResult($result) {
if ($result == "" || $result == false) {
throw new Exception("{{ Invalid Data }}");
}
}
function ShotTime($time_mcrypt, $time_openssl)
{
echo "<br/>Time (mcrypt) :{$time_mcrypt} ms";
echo "<br/>Time (openssl) :{$time_openssl} ms";
}