comparison db/usr/sevilNatas/etc/translator.php @ 418:bc3737021c3c draft

translator
author sevil <sevil@sevilnatas.ano>
date Wed, 02 Mar 2011 09:34:43 -0600
parents
children
comparison
equal deleted inserted replaced
417:a7da0e1504e4 418:bc3737021c3c
1 <?
2 static $binary;
3 static $ascii;
4 static $hex;
5 static $b64;
6 static $char;
7
8 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
9 <html xmlns="http://www.w3.org/1999/xhtml">
10 <head>
11 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
12 <title>[sevilNatas@anoNet]:~# Translator</title>
13 <link rel="stylesheet" type="text/css" href="../main.css" />
14 <style>
15 .ff{font-size: 10px;
16 font-family:verdana,arial,helvetica,sans;
17 color: #333333;
18 background: #eee;
19 }
20 .btn{
21 font-size: 8px;
22 font-family:verdana,arial,helvetica,sans;
23 color: #333333;
24 background: #eee;
25 }
26 BODY{
27 scrollbar-3dlight-color:#999999;
28 scrollbar-arrow-color:#999999;
29 scrollbar-base-color:#DDDDDD;
30 scrollbar-darkshadow-color:#999999;
31 scrollbar-face-color:#DDDDDD;
32 scrollbar-highlight-color:#DDDDDD;
33 scrollbar-shadow-color:#DDDDDD;
34 scrollbar-track-color:#CCCCCC;
35 }
36
37 </style>
38 </head>
39 <body>
40
41 <!-- Begin Wrapper -->
42 <div id="wrapper">
43 <!-- Begin Header -->
44 <div id="header">
45 <h1>Translator, Binary</h1>
46 </div>
47 <!-- End Header -->
48 <!-- Begin Naviagtion -->
49 <div id="navigation">
50 <a href="../index.shtml" target="_top">Main</a> |
51 <a href="../pastebin/" target="_top">Pastebin</a> |
52 <a href="../translator/" target="_top">Translator</a> |
53 <a href="../library.html" target="_top">Library</a> |
54 <a href="../chat.html" target="_top">IRC</a> |
55 <a href="../math.html" target="_top">Mathematics</a> |
56 <a href="http://www.sevilwiki.ano/" target="_blank">
57 sevilWiki <img style="border:0px solid black;" src="../imgs/external.png" alt="(external link)" width="10" height="10" />
58 </a>
59 </div>
60 <!-- End Naviagtion -->
61 <!-- Begin Content -->
62 <div id="content">
63
64
65 </head>
66 <body bgcolor="#ffffff" text="#000">
67
68 <div style="float: left; width: 90px;"><b>Please note:</b></div>
69 <div style="float: left;"> This application encodes and decodes
70 <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> and
71 <a href="http://en.wikipedia.org/wiki/ANSI">ANSI</a>
72 text. <br />Only codepoints &lt; 128 are ASCII.</div>
73 <div style="clear: both;"></div><br />
74
75
76 <center>
77 <table border=0 cellspacing=0 cellpadding=0><tr><td align=center>
78 <font face="verdana,arial,helvetica" size=1>
79
80 <table border=0 cellspacing=0 cellpadding=10>
81 <tr><form method="POST"><td align=center valign=top>
82 <font face="verdana,arial,helvetica" size=1>
83
84 <b>[ <a href="../ascii/">TEXT</a> ]</b><br />
85 <textarea cols=48 rows=15 wrap="virtual" name="ascii" class="ff"><?php
86
87 set_magic_quotes_runtime(0);
88 foreach($_POST as $key=>$val){ $$key = stripslashes($val); }
89
90 #$_POST[ascii] = str_replace("\\'","'",$_POST[ascii]);
91 #$_POST[ascii] = str_replace("\\\"","\"",$_POST[ascii]);
92 #$_POST[ascii] = str_replace("\\\\","\\",$_POST[ascii]);
93 if($ascii != "") print htmlentities($ascii);
94 else {
95
96 if($binary != "") {
97 $binary_ = preg_replace("/[^01]/","", $binary);
98 for($i = 0; $i < strlen($binary_); $i = $i + 8)
99 $ascii = $ascii.chr(bindec(substr($binary_, $i, 8)));
100 }
101
102 if($hex != "") {
103 $hex_ = preg_replace("/[^0-9a-fA-F]/","", $hex);
104 for($i = 0; $i < strlen($hex_); $i = $i + 2)
105 $ascii = $ascii.chr(hexdec(substr($hex_, $i, 2)));
106 }
107
108 if($b64 != "") {
109 //$ascii = gzinflate($gzip);
110 $ascii = base64_decode($b64);
111 }
112
113 if($char != "") {
114 $char_ = preg_split("/\\D+/",trim($char));
115 foreach ($char_ as $key)
116 $ascii = $ascii.chr($key);
117 }
118
119 echo htmlentities($ascii);
120 }
121
122 ?></textarea>
123 <br />
124 <input type="submit" class="btn" value="&lt; ENCODE &gt;">
125 </td></form><form method="POST"><td align=center valign=top>
126 <font face="verdana,arial,helvetica" size=1>
127
128 <b>2 [ <a href="http://en.wikipedia.org/wiki/Binary_numeral_system"><acronym title="Binary">BINARY</acronym></a> ]</b><br />
129 <textarea cols=48 rows=15 wrap="virtual" name="binary" class="ff"><?php
130
131 if($binary != "") echo $binary;
132 else if($ascii != "") {
133 $val = strval(decbin(ord(substr($ascii, 0, 1))));
134 echo str_repeat("0", 8-strlen($val)).$val;
135 for($i = 1; $i < strlen($ascii); $i = $i + 1) {
136 $val = strval(decbin(ord(substr($ascii, $i, 1))));
137 echo " ".str_repeat("0", 8-strlen($val)).$val;
138 }
139 }
140
141 ?></textarea>
142 <br />
143 <input type="submit" class="btn" value="&lt; DECODE &gt;">
144 </td></form><form method="POST"><td align=center valign=top>
145 <font face="verdana,arial,helvetica" size=1>
146
147 <b>4 [ <a href="http://en.wikipedia.org/wiki/Hexidecimal"><acronym title="Hexidecimal">HEX</acronym></a> ]</b><br />
148 <textarea cols=48 rows=15 wrap="virtual" name="hex" class="ff"><?php
149
150 if($hex != "") echo $hex;
151 else if($ascii != "") {
152 $val = dechex(ord(substr($ascii, 0, 1)));
153 echo str_repeat("0", 2-strlen($val)).$val;
154 for($i = 1; $i < strlen($ascii); $i = $i + 1) {
155 $val = dechex(ord(substr($ascii, $i, 1)));
156 echo " ".str_repeat("0", 2-strlen($val)).$val;
157 }
158 }
159
160
161 ?></textarea>
162 <br />
163 <input type="submit" class="btn" value="&lt; DECODE &gt;">
164 </td></tr></form><br />
165 <?/*
166 <!--OCT-->
167 <form method="POST"><tr><td align=center valign=top>
168 <font face="verdana,arial,helvetica" size=1>
169
170 <b>3 [ OCT ]</b><br />
171 <textarea cols=48 rows=15 wrap="virtual" name="oct" class="ff"><?php
172
173 if($oct != "") echo $oct;
174 else if($ascii != "") {
175 $val = 0;
176 for($i = 0; $i < strlen($ascii); $i = $i + 3) {
177 $val = ord(substr($ascii, $i, 1));
178 $val = $val * 256 + ord(substr($ascii, $i + 1, 1));
179 $val = $val * 256 + ord(substr($ascii, $i + 2, 1));
180 //echo "debug $val topbit = ".intval($val / 64 / 64 / 64)."\n";
181 printf("%08d",oct_decode($val));
182 $val = 0;
183 }
184 if($val > 0) echo oct_decode($val);
185 }
186
187 function b64_decode($val) {
188 $tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
189 if($val >= 64) return oct_decode(intval($val / 64))."".substr($tab,$val%64,1);
190 return substr($tab,$val,1);
191 }
192 function oct_decode($val) {
193 if($val >= 8) return oct_decode(intval($val / 8))."".($val%8);
194 return "".$val;
195 }
196 */
197 ?></textarea>
198 <br />
199 <? //<input type="submit" class="btn" value="&lt; DECODE &gt;">?>
200 </td></form>
201
202 <!--BASE 64-->
203 <form method="POST"><tr><td align=center valign=top>
204 <font face="verdana,arial,helvetica" size=1>
205
206 <b>6 [ <a href="http://en.wikipedia.org/wiki/Base64">BASE64</a> ]</b><br />
207 <textarea cols=48 rows=15 wrap="virtual" name="b64" class="ff"><?php
208
209 if($b64 != "") echo $b64;
210 else if($ascii != "") {
211 echo base64_encode($ascii);
212 //$gzip = gzencode($ascii, 9);
213 //echo substr($gzip,10,strlen($gzip)-19);
214 }
215
216 ?></textarea>
217 <br />
218 <input type="submit" class="btn" value="&lt; DECODE &gt;">
219 </td></form>
220
221 <!--CHAR-->
222 <form method="POST"><td align=center valign=top>
223 <font face="verdana,arial,helvetica" size=1>
224
225 <b>[ DEC / CHAR ]</b><br />
226 <textarea cols=48 rows=15 wrap="virtual" name="char" class="ff"><?php
227
228 if($char != "") echo $char;
229 else if($ascii != "") {
230 echo ord(substr($ascii, 0, 1));
231 for($i = 1; $i < strlen($ascii); $i = $i + 1)
232 echo " ".ord(substr($ascii, $i, 1));
233 }
234
235
236 ?></textarea>
237 <br />
238 <input type="submit" class="btn" value="&lt; DECODE &gt;">
239 </td></form><form method="POST"><td align=center valign=top>
240 <font face="verdana,arial,helvetica" size=1>
241
242
243 <b>[ MESSAGE DIGEST / CHECK SUM ]</b><br />
244 <textarea cols=48 rows=15 wrap="virtual" name="char" class="ff"><?php
245
246 $tmpfname = tempnam("/tmp", "xlate");
247 $handle = fopen($tmpfname, "w");
248 fwrite($handle, $ascii);
249 fclose($handle);
250
251 #echo "MD2: ".exec("/home/paulscho/bin/md2 $tmpfname")."\n";
252 echo "MD2: ".openssl("md2",$tmpfname)."\n";
253 #echo "MD4: ".exec("/home/paulscho/bin/md4 $tmpfname")."\n";
254 echo "MD4: ".openssl("md4",$tmpfname)."\n";
255 echo "MD5: ".md5($ascii)."\n";
256 echo "CRC 8, ccitt, 16, 32 : ".
257 # exec("/home/paulscho/bin/crc8 $tmpfname").", ".
258 # exec("/home/paulscho/bin/crcc $tmpfname").", ".
259 # exec("/home/paulscho/bin/crc16 $tmpfname").", ".
260 exec("/usr/bin/crc32 $tmpfname")."\n\n";
261 #crc32($ascii)."\n\n";
262 echo "CRYPT (form: $ MD5? $ SALT $ CRYPT):\n".crypt($ascii)."\n";
263 echo " (form: SALT[2] CRYPT[11]):\n".crypt($ascii,"ps")."\n\n";
264 #include("sha1lib.class.inc.php");
265 #$sha = new Sha1Lib;
266
267 #echo "SHA1:".base64_encode($sha->str_sha1($ascii))."\n";
268 $sha1 = explode("= ",exec("/usr/bin/openssl dgst -sha1 $tmpfname"));
269 echo "SHA1: $sha1[1]";
270 #$ascii = $sha->str_sha1($ascii);
271 #for($i = 1; $i < strlen($ascii); $i = $i + 1) {
272 # $val = dechex(ord(substr($ascii, $i, 1)));
273 # echo "".str_repeat("0", 2-strlen($val)).$val;
274 #}
275 echo "\n";
276 #echo "RIPEMD-160: ".splitn(60,exec("/home/paulscho/bin/ripemd160 $tmpfname"))."\n";
277 echo "RIPEMD-160: ".splitn(60,openssl("rmd160",$tmpfname))."\n";
278 #echo "SHA2-256: ".split32(exec("/home/paulscho/bin/sha2-256 $tmpfname"))."\n";
279 #echo "SHA2-384: ".split32(exec("/home/paulscho/bin/sha2-384 $tmpfname"))."\n";
280 #echo "SHA2-512: ".split32(exec("/home/paulscho/bin/sha2-512 $tmpfname"))."\n";
281 unlink($tmpfname);
282
283 function openssl($dgst = "sha1", $filename) {
284 $sha1 = explode("= ",exec("/usr/bin/openssl dgst -$dgst $filename"));
285 return trim($sha1[1]);
286 }
287
288 ?></textarea>
289 <br />
290 (This cannot be decoded<sup>*</sup>)
291 </td></tr></form></table>
292
293
294
295 <br />
296 <sup>*</sup>Cannot be decoded easily (within my lifespan).
297 </center>
298 <br /><br />
299 <?
300 function split32($text) {
301 $string = "";
302 for($i = 0; $i < strlen($text); $i = $i + 32) {
303 $string = "$string\n ".substr($text, $i, 32);
304 }
305 return $string;
306 }
307 function splitn($n,$text) {
308 $string = "";
309 for($i = 0; $i < strlen($text); $i = $i + $n) {
310 $string = "$string\n ".substr($text, $i, $n);
311 }
312 return $string;
313 }
314 ?>
315
316 </div>
317 <!-- Begin Content -->
318 </div>
319 <!-- End Wrapper -->
320
321 </body>
322 </html>