forked from mattiasgeniar/Encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
241 lines (196 loc) · 8.93 KB
/
index.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
// Check for form submit
if (!isset($_POST['cmdEncode']) && !isset($_POST['cmdDecode'])) {
// User has not yet submitted
$_POST['chkBasics'] = true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Decoder - Encoder: UTF8, UTF16, ...</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-4635324-7']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
<body>
<div id="header">
<div id="main">
<h1><u>De</u>code, <u>En</u>code or <u>Ob</u>fuscate your string</h1>
<p>This is used to obfuscate your string or code, to encode or decode a certain value.</p>
<hr />
<form method="post" action="index.php">
<p>Enter your string in the textarea below. Am I missing a popular technique? <a href="mailto:[email protected]">Let me know!</a></p>
<textarea name="txtCode" cols="80" rows="6"><?= isset($_POST['txtCode']) ? $_POST['txtCode'] : '' ?></textarea><br />
<input type="checkbox" name="chkBasics" id="chkBasics" <?= isset($_POST['chkBasics']) ? 'checked' : '' ?> /> <label for="chkBasics">Include basic encoding/decoding (HTML, UTF-8, base64, URL encode, ...)</label><br />
<input type="checkbox" name="chkOneWay" id="chkOneWay" <?= isset($_POST['chkOneWay']) ? 'checked' : '' ?> /> <label for="chkOneWay">Include one-way encryption (MD5, SHA1, RipeMD, Adler, Haval...)</label><br />
<input type="checkbox" name="chkObfuscate" id="chkObfuscate" <?= isset($_POST['chkObfuscate']) ? 'checked' : '' ?> /> <label for="chkObfuscate">Include code obfuscation (Javascript, SQL, HTML)</label><br />
<input type="submit" name="cmdEncode" value="Encode string" class="submit_button" /> <input type="submit" name="cmdDecode" value="Decode string" class="submit_button" />
</form>
<?php
if (isset($_POST['cmdEncode']) && strlen($_POST['txtCode']) > 0) {
// Encode this string
$txtCode = $_POST['txtCode'];
$arrCharCode = array();
$arrCharCodeSQL = array();
$arrCharCodeHexHtml = array();
$arrCharCodeDecHtml = array();
$arrCharCodeHexShortHtml = array();
for ($i = 0; $i < strlen($txtCode); $i++) {
$arrCharCode[] = ord($txtCode[$i]);
$arrCharCodeSQL[] = "CHAR(" . ord($txtCode[$i]) . ")";
$arrCharCodeHexHtml[] = "&#x" . dechex(ord($txtCode[$i]));
$arrCharCodeDecHtml[] = "&#" . ord($txtCode[$i]);
$arrCharCodeHexShortHtml[] = "%" . dechex(ord($txtCode[$i]));
}
echo "<br /><h1>Encoding results</h1>\n\n";
if (isset($_POST['chkBasics'])) {
echo "<h1>Basic encoding</h1>\n";
// UTF-7
echo "<h2>UTF-7 encode</h2>\n";
echo "<xmp>" . imap_utf7_encode($txtCode) . "</xmp>\n\n";
// UTF-8
echo "<h2>UTF-8 encode</h2>\n";
echo "<xmp>" . utf8_encode($txtCode) . "</xmp>\n\n";
// UTF-16
echo "<h2>UTF-16 encode</h2>\n";
echo "<xmp>" . mb_convert_encoding($txtCode, "UTF-16", "auto") . "</xmp>\n\n";
// UTF-32
echo "<h2>UTF-32 encode</h2>\n";
echo "<xmp>" . mb_convert_encoding($txtCode, "UTF-32", "auto") . "</xmp>\n\n";
// rawurlencode
echo "<h2>RAW URL encode</h2>\n";
echo "<xmp>" . rawurlencode($txtCode) . "</xmp>\n\n";
// urlencode
echo "<h2>URL encode simple</h2>\n";
echo "<xmp>" . urlencode($txtCode) . "</xmp>\n\n";
// urlencode
echo "<h2>URL encode full</h2>\n";
echo "<xmp>" . implode("", $arrCharCodeHexShortHtml) . "</xmp>\n\n";
// HTML
echo "<h2>HTML encode</h2>\n";
echo "<xmp>" . htmlentities($txtCode) . "</xmp>\n\n";
// base64
echo "<h2>Base64 encode</h2>\n";
echo "<xmp>" . base64_encode($txtCode) . "</xmp>\n\n";
// uuencode
echo "<h2>UUencode</h2>\n";
echo "<xmp>" . convert_uuencode($txtCode) . "</xmp>\n\n";
}
if (isset($_POST['chkOneWay'])) {
echo "<h1>One way encryption</h1>\n";
foreach (hash_algos() as $hash_algo) {
echo "<h2>Hash: " . $hash_algo . "</h2>\n";
echo "<xmp>" . hash($hash_algo, $txtCode) . "</xmp>\n\n";
}
}
if (isset($_POST['chkObfuscate'])) {
echo "<h1>Obfuscation: JavaScript</h1>\n";
// String.fromCharCode() in Javascript
echo "<h2>fromCharCode()</h2>\n";
echo "<xmp>document.write(String.fromCharCode(" . implode(",", $arrCharCode) . "));</xmp>\n\n";
// unescape() in Javascript
echo "<h2>unescape()</h2>\n";
echo "<xmp>document.write(unescape(\"" . implode("", $arrCharCodeHexShortHtml) . "\"));</xmp>\n\n";
echo "<h1>Obfuscation: SQL</h1>\n";
// concat() char's
echo "<h2>CONTACT of CHAR()'s</h2>\n";
echo "<xmp>CONCAT(" . implode(",", $arrCharCodeSQL) . ")</xmp>\n\n";
// char()
echo "<h2>CHAR()</h2>\n";
echo "<xmp>CHAR(" . implode(",", $arrCharCode) . ")</xmp>\n\n";
echo "<h1>Obfuscation: HTML</h1>\n";
// hexadecimal
echo "<h2>HTML Hexadecimal with optional semicolons</h2>\n";
echo "<xmp>" . implode(";", $arrCharCodeHexHtml) . ";</xmp>\n\n";
// decimal
echo "<h2>HTML Decimal with optional semicolons</h2>\n";
echo "<xmp>" . implode(";", $arrCharCodeDecHtml) . ";</xmp>\n\n";
}
} elseif (isset($_POST['cmdDecode']) && strlen($_POST['txtCode']) > 0) {
// Decode this string
$txtCode = $_POST['txtCode'];
if (isset($_POST['chkBasics'])) {
echo "<h1>Basic encoding</h1>\n";
// UTF-7
echo "<h2>UTF-7 decoded</h2>\n";
echo "<xmp>" . imap_utf7_decode($txtCode) . "</xmp>\n\n";
// UTF-8
echo "<h2>UTF-8 decoded</h2>\n";
echo "<xmp>" . utf8_decode($txtCode) . "</xmp>\n\n";
// UTF-16
echo "<h2>UTF-16 decoded to UTF-8</h2>\n";
echo "<xmp>" . mb_convert_encoding($txtCode, "UTF-8", array("UTF-16")) . "</xmp>\n\n";
// UTF-32
echo "<h2>UTF-32 decoded to UTF-8</h2>\n";
echo "<xmp>" . mb_convert_encoding($txtCode, "UTF-8", array("UTF-32")) . "</xmp>\n\n";
// rawurlencode
echo "<h2>RAW URL decoded</h2>\n";
echo "<xmp>" . rawurldecode($txtCode) . "</xmp>\n\n";
// urlencode
echo "<h2>URL encode</h2>\n";
echo "<xmp>" . urlencode($txtCode) . "</xmp>\n\n";
// HTML
echo "<h2>HTML entities decoded</h2>\n";
echo "<xmp>" . html_entity_decode($txtCode) . "</xmp>\n\n";
// base64
echo "<h2>Base64 decoded</h2>\n";
echo "<xmp>" . base64_decode($txtCode) . "</xmp>\n\n";
// uuencode
echo "<h2>UUdecoded</h2>\n";
echo "<xmp>" . convert_uudecode($txtCode) . "</xmp>\n\n";
}
}
?>
</div>
<div id="footer">
String decoder & encoder | Created by <a href="https://ma.ttias.be" target="_blank">Mattias Geniar</a> | Source on <a href="https://github.com/mattiasgeniar/Encoder" target="_blank">Github</a>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>
<script>
(function() {
// Make copy button for all xmp tags
var xmps = document.getElementsByTagName('xmp');
for (var count = 0; count < xmps.length; count++) {
var id = 'copy-' + count;
var xmp = xmps[count];
xmp.id = id;
var button = document.createElement('a');
button.setAttribute("data-clipboard-target", "#" + id);
button.innerText = 'Copy text';
var title = xmp.previousElementSibling;
title.appendChild(button);
}
var clipboard = new Clipboard('a[data-clipboard-target]');
clipboard.on('success', function(e) {
var trigger = e.trigger;
trigger.innerText = 'Copied!';
setTimeout(function() {
trigger.innerText = 'Copy text';
}, 2000);
e.clearSelection();
});
clipboard.on('error', function(e) {
var trigger = e.trigger;
trigger.innerText = 'Press Ctrl+c or Cmd+c to copy.';
setTimeout(function() {
trigger.innerText = 'Copy text';
}, 2000);
});
}());
</script>
</body>
</html>