This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathModhex_Calculator.php
134 lines (127 loc) · 4.33 KB
/
Modhex_Calculator.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
* Created on May 25, 2009
*
*/
require_once 'Modhex.php';
$FMT_TEXT = 'Plain text';
$FMT_DEC = 'Number';
$FMT_MODHEX = 'Modhex';
$FMT_B64 = 'Base64';
$FMT_HEX = 'Hex';
$FMT_OTP = 'OTP';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<title>Modhex Calculator</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
input[type="radio"] {
width: 45px;
}
</style>
</head>
<body onLoad="document.getElementById('srctext').focus();">
<div id="stripe">
</div>
<div id="container">
<div id="logoArea">
<img src="yubicoLogo.jpg" alt="Yubico Logo" width="150" height="75"/>
</div>
<div id="greenBarContent">
<div id="greenBarImage">
<img src="yubikey.jpg" alt="yubikey" width="150" height="89"/>
</div>
<div id="greenBarText">
<h3>
Modhex Calculator
</h3>
</div>
</div>
<div id="bottomContent">
<?php
$srctext = trim($_REQUEST["srctext"]);
$srcfmt = $_REQUEST["srcfmt"];
$srcfmt_org = $srcfmt? $srcfmt: "P";
$srcfmt_desc = '';
if (strlen($srctext) > 0) {
if($srcfmt == "O") {
$srcfmt_desc = $FMT_OTP;
$srctext = substr($srctext, 0, 12);
$srcfmt = "M";
}
$b64txt = $srctext;
if($srcfmt == "P") {
$srcfmt_desc = $FMT_TEXT;
$b64txt = base64_encode($srctext);
} else if ($srcfmt == "H") {
$srcfmt_desc = $FMT_HEX;
$hexval = $srctext;
$b64txt = hexToB64($hexval);
//echo 'Test B64 : '.$b64txt.' :: '.$hexval;
} else if ($srcfmt == "M") {
if($srcfmt_desc == '') {
$srcfmt_desc = $FMT_MODHEX;
}
if((strlen($srctext) % 2) == 1) {
$srctext = 'c' . $srctext;
}
$b64txt = modhexToB64($srctext);
} else if ($srcfmt == "N") {
$srcfmt_desc = $FMT_DEC;
//$numval = intval($srctext);
$numval = gmp_init($srctext, 10);
$hexval = gmp_strval($numval,16);
//echo 'Test Val : '.$numval.' :: '.$hexval;
$b64txt = hexToB64($hexval);
//echo 'Test B64 : '.$b64txt;
} else {
$srcfmt_desc = $FMT_B64;
}
//$devId_b64 = modhexToB64($devId);
?>
<fieldset>
<legend><b>Result</b></legend>
<b>Input string: </b><?php echo htmlspecialchars($srctext);?> (<?php echo $srcfmt_desc;?>)<br/><br>
<b>Output string</b> (in various formats):
<ul>
<li><?php echo $FMT_TEXT . ': ' . htmlspecialchars(base64_decode($b64txt)); ?></li>
<li><?php echo $FMT_DEC . ': ' . htmlspecialchars(gmp_strval(gmp_init(b64ToHex($b64txt),16))); ?></li>
<li><?php echo $FMT_MODHEX . ' encoded: ' . htmlspecialchars(b64ToModhex($b64txt)); ?></li>
<li><?php echo $FMT_B64 . ' encoded: ' . htmlspecialchars($b64txt); ?></li>
<li><?php echo $FMT_HEX . ' encoded: ' . htmlspecialchars(b64ToHex($b64txt)); ?></li>
</ul>
</fieldset>
<br>
<?php
}
?>
<form action=Modhex_Calculator.php method=post autocomplete=off>
<fieldset>
<legend><b>Number scheme calculator</b></legend>
<ol>
<li>Choose format.</li>
<li>Enter string.</li>
<li>Press "Convert to all formats" button.</li>
</ol>
<b>Source format:</b><br/>
<input type="radio" name="srcfmt" value="P" <?php echo ($srcfmt_org == "P")?'checked':''; ?>>Plain text<br/>
<input type="radio" name="srcfmt" value="N" <?php echo ($srcfmt_org == "N")?'checked':''; ?>>Number<br/>
<input type="radio" name="srcfmt" value="B" <?php echo ($srcfmt_org == "B")?'checked':''; ?>>Base64<br/>
<input type="radio" name="srcfmt" value="H" <?php echo ($srcfmt_org == "H")?'checked':''; ?>>Hex<br/>
<input type="radio" name="srcfmt" value="O" <?php echo ($srcfmt_org == "O")?'checked':''; ?>>OTP<br/>
<input type="radio" name="srcfmt" value="M" <?php echo ($srcfmt_org == "M")?'checked':''; ?>>Modhex<br/><br/>
<b>String:</b>
<input name="srctext" id="srctext" value="<?php echo htmlspecialchars($srctext); ?>" size=50 maxlength=50><br/><br/>
<input type="submit" value="Convert to all formats">
</fieldset>
</form>
</div>
</div>
</body>
</html>