jesobreira

Translator, binary

Aug 12th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.75 KB | None | 0 0
  1. <?
  2.  
  3. error_reporting(0);
  4. static $binary;
  5. static $ascii;
  6. static $hex;
  7. static $b64;
  8. static $char;
  9.  
  10. ?><html>
  11. <head>
  12. <title>Binary Translator</title>
  13. <META NAME="description" CONTENT="Online tool to translate ASCII/ANSI, HEX, Binary, Base64, etc... Encoder/Decoder with MD2,
  14.  
  15. MD4, MD5, SHA1+2, RIPEMD, CRC, etc. hashing algorithms.">
  16. <META NAME="keywords" CONTENT="binary encoder, binary decoder, binary translator, binary tools, binary converter, hexadecimal
  17.  
  18. encoder/decoder, base 64, MD5, Message-Digest algorithm, CRC, Cyclic Redundancy Check, SHA, Secure Hash Algorithm, RIPEMD,
  19.  
  20. RACE Integrity Primitives Evaluation Message Digest">
  21. <style>
  22. .ff{font-size: 10px;
  23.     font-family:verdana,arial,helvetica,sans;
  24.     color: #333333;
  25.     background: #333344;
  26.     }
  27. .btn{
  28.     font-size: 8px;
  29.     font-family:verdana,arial,helvetica,sans;
  30.     color: #333333;
  31.     background: #eee;
  32.     }
  33. BODY{
  34. scrollbar-3dlight-color:#999999;
  35. scrollbar-arrow-color:#999999;
  36. scrollbar-base-color:#DDDDDD;
  37. scrollbar-darkshadow-color:#999999;
  38. scrollbar-face-color:#DDDDDD;
  39. scrollbar-highlight-color:#DDDDDD;
  40. scrollbar-shadow-color:#DDDDDD;
  41. scrollbar-track-color:#CCCCCC;
  42. }
  43.  
  44. </style>
  45.  
  46. </head>
  47. <body bgcolor="#ffffff" text="#000">
  48.  
  49. <center>
  50. <table border=0 cellspacing=0 cellpadding=0><tr><td align=center>
  51. <font face="verdana,arial,helvetica" size=1>
  52. <h1>TRANSLATOR, BINARY</h1>
  53. <p><b>Please note:</b><br> This application encodes and decodes
  54. <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> and
  55. <a href="http://en.wikipedia.org/wiki/ANSI">ANSI</a>
  56. text.  <br>Only codepoints &lt; 128 are ASCII.  This is provided for educational and entertainment use only.</p>
  57.  
  58. <table border=0 cellspacing=0 cellpadding=10>
  59. <tr><form method="POST"><td align=center valign=top>
  60. <font face="verdana,arial,helvetica" size=1>
  61.  
  62. <b>[ <a href="../ascii/">TEXT</a> ]</b><br>
  63. <textarea cols=48 rows=15 wrap="virtual" name="ascii" class="ff"><?php
  64.  
  65. set_magic_quotes_runtime(0);
  66. foreach($_POST as $key=>$val){ $$key = stripslashes($val); }
  67.  
  68. #$_POST[ascii] = str_replace("\\'","'",$_POST[ascii]);
  69. #$_POST[ascii] = str_replace("\\\"","\"",$_POST[ascii]);
  70. #$_POST[ascii] = str_replace("\\\\","\\",$_POST[ascii]);
  71. if($ascii != "") print htmlentities($ascii);
  72. else {
  73.  
  74. if($binary != "") {
  75.     $binary_ = preg_replace("/[^01]/","", $binary);
  76.     for($i = 0; $i < strlen($binary_); $i = $i + 8)
  77.     $ascii = $ascii.chr(bindec(substr($binary_, $i, 8)));
  78. }
  79.  
  80. if($hex != "") {
  81.     $hex_ = preg_replace("/[^0-9a-fA-F]/","", $hex);
  82.     for($i = 0; $i < strlen($hex_); $i = $i + 2)
  83.     $ascii = $ascii.chr(hexdec(substr($hex_, $i, 2)));
  84. }
  85.  
  86. if($b64 != "") {
  87.     //$ascii = gzinflate($gzip);
  88.     $ascii = base64_decode($b64);
  89. }
  90.  
  91. if($char != "") {
  92.     $char_ = preg_split("/\\D+/",trim($char));
  93.     foreach ($char_ as $key)
  94.     $ascii = $ascii.chr($key);
  95. }
  96.  
  97. echo htmlentities($ascii);
  98. }
  99.  
  100. ?></textarea>
  101. <br>
  102. <input type="submit" class="btn" value="&lt; ENCODE &gt;">
  103. </td></form><form method="POST"><td align=center valign=top>
  104. <font face="verdana,arial,helvetica" size=1>
  105.  
  106. <b>2 [ <a href="http://en.wikipedia.org/wiki/Binary_numeral_system"><acronym title="Binary">BINARY</acronym></a> ]</b><br>
  107. <textarea cols=48 rows=15 wrap="virtual" name="binary" class="ff"><?php
  108.  
  109. if($binary != "") echo $binary;
  110. else if($ascii != "") {
  111. $val = strval(decbin(ord(substr($ascii, 0, 1))));
  112. echo str_repeat("0", 8-strlen($val)).$val;
  113. for($i = 1; $i < strlen($ascii); $i = $i + 1) {
  114. $val = strval(decbin(ord(substr($ascii, $i, 1))));
  115. echo " ".str_repeat("0", 8-strlen($val)).$val;
  116. }
  117. }
  118.  
  119. ?></textarea>
  120. <br>
  121. <input type="submit" class="btn" value="&lt; DECODE &gt;">
  122. </td></form><form method="POST"><td align=center valign=top>
  123. <font face="verdana,arial,helvetica" size=1>
  124.  
  125. <b>4 [ <a href="http://en.wikipedia.org/wiki/Hexidecimal"><acronym title="Hexidecimal">HEX</acronym></a> ]</b><br>
  126. <textarea cols=48 rows=15 wrap="virtual" name="hex" class="ff"><?php
  127.  
  128. if($hex != "") echo $hex;
  129. else if($ascii != "") {
  130. $val = dechex(ord(substr($ascii, 0, 1)));
  131. echo str_repeat("0", 2-strlen($val)).$val;
  132. for($i = 1; $i < strlen($ascii); $i = $i + 1) {
  133.   $val = dechex(ord(substr($ascii, $i, 1)));
  134.   echo " ".str_repeat("0", 2-strlen($val)).$val;
  135. }
  136. }
  137.  
  138.  
  139. ?></textarea>
  140. <br>
  141. <input type="submit" class="btn" value="&lt; DECODE &gt;">
  142. </td></tr></form>
  143. <?
  144. <!--OCT-->
  145. <form method="POST"><tr><td align=center valign=top>
  146. <font face="verdana,arial,helvetica" size=1>
  147.  
  148. <b>3 [ OCT ]</b><br>
  149. <textarea cols=48 rows=15 wrap="virtual" name="oct" class="ff"><?php
  150.  
  151. if($oct != "") echo $oct;
  152. else if($ascii != "") {
  153.     $val = 0;
  154.     for($i = 0; $i < strlen($ascii); $i = $i + 3) {
  155.         $val = ord(substr($ascii, $i, 1));
  156.         $val = $val * 256 + ord(substr($ascii, $i + 1, 1));
  157.         $val = $val * 256 + ord(substr($ascii, $i + 2, 1));
  158.         //echo "debug $val topbit = ".intval($val / 64 / 64 / 64)."\n";
  159.         printf("%08d",oct_decode($val));
  160.         $val = 0;
  161.     }
  162.     if($val > 0) echo oct_decode($val);
  163. }
  164.  
  165. function b64_decode($val) {
  166. $tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  167. if($val >= 64) return oct_decode(intval($val / 64))."".substr($tab,$val%64,1);
  168. return substr($tab,$val,1);
  169. }
  170. function oct_decode($val) {
  171. if($val >= 8) return oct_decode(intval($val / 8))."".($val%8);
  172. return "".$val;
  173. }
  174.  
  175. ?></textarea>
  176. <br>
  177. <? //<input type="submit" class="btn" value="&lt; DECODE &gt;">?>
  178. </td></form>
  179.  
  180. <!--BASE 64-->
  181. <form method="POST"><tr><td align=center valign=top>
  182. <font face="verdana,arial,helvetica" size=1>
  183.  
  184. <b>6 [ <a href="http://en.wikipedia.org/wiki/Base64">BASE64</a> ]</b><br>
  185. <textarea cols=48 rows=15 wrap="virtual" name="b64" class="ff"><?php
  186.  
  187. if($b64 != "") echo $b64;
  188. else if($ascii != "") {
  189. echo base64_encode($ascii);
  190. //$gzip = gzencode($ascii, 9);
  191. //echo substr($gzip,10,strlen($gzip)-19);
  192. }
  193.  
  194. ?></textarea>
  195. <br>
  196. <input type="submit" class="btn" value="&lt; DECODE &gt;">
  197. </td></form>
  198.  
  199. <!--CHAR-->
  200. <form method="POST"><td align=center valign=top>
  201. <font face="verdana,arial,helvetica" size=1>
  202.  
  203. <b>[ DEC / CHAR ]</b><br>
  204. <textarea cols=48 rows=15 wrap="virtual" name="char" class="ff"><?php
  205.  
  206. if($char != "") echo $char;
  207. else if($ascii != "") {
  208. echo ord(substr($ascii, 0, 1));
  209. for($i = 1; $i < strlen($ascii); $i = $i + 1)
  210. echo " ".ord(substr($ascii, $i, 1));
  211. }
  212.  
  213.  
  214. ?></textarea>
  215. <br>
  216. <input type="submit" class="btn" value="&lt; DECODE &gt;">
  217. </td></form><form method="POST"><td align=center valign=top>
  218. <font face="verdana,arial,helvetica" size=1>
  219.  
  220.  
  221. <b>[ MESSAGE DIGEST / CHECK SUM ]</b><br>
  222. <textarea cols=48 rows=15 wrap="virtual" name="char" class="ff"><?php
  223.  
  224. $tmpfname = tempnam("/tmp", "xlate");
  225. $handle = fopen($tmpfname, "w");
  226. fwrite($handle, $ascii);
  227. fclose($handle);
  228.  
  229. #echo "MD2: ".exec("/home/paulscho/bin/md2 $tmpfname")."\n";
  230. echo "MD2: ".openssl("md2",$tmpfname)."\n";
  231. #echo "MD4: ".exec("/home/paulscho/bin/md4 $tmpfname")."\n";
  232. echo "MD4: ".openssl("md4",$tmpfname)."\n";
  233. echo "MD5: ".md5($ascii)."\n";
  234. echo "CRC 8, ccitt, 16, 32 : ".
  235. #  exec("/home/paulscho/bin/crc8 $tmpfname").", ".
  236. #  exec("/home/paulscho/bin/crcc $tmpfname").", ".
  237. #  exec("/home/paulscho/bin/crc16 $tmpfname").", ".
  238.  exec("/usr/bin/crc32 $tmpfname")."\n\n";
  239. #crc32($ascii)."\n\n";
  240. echo "CRYPT (form: $ MD5? $ SALT $ CRYPT):\n".crypt($ascii)."\n";
  241. echo "      (form: SALT[2] CRYPT[11]):\n".crypt($ascii,"ps")."\n\n";
  242. #include("sha1lib.class.inc.php");
  243. #$sha = new Sha1Lib;
  244.  
  245. #echo "SHA1:".base64_encode($sha->str_sha1($ascii))."\n";
  246. $sha1 = explode("= ",exec("/usr/bin/openssl dgst -sha1 $tmpfname"));
  247. echo "SHA1: $sha1[1]";
  248. #$ascii = $sha->str_sha1($ascii);
  249. #for($i = 1; $i < strlen($ascii); $i = $i + 1) {
  250. #  $val = dechex(ord(substr($ascii, $i, 1)));
  251. #  echo "".str_repeat("0", 2-strlen($val)).$val;
  252. #}
  253. echo "\n";
  254. #echo "RIPEMD-160: ".splitn(60,exec("/home/paulscho/bin/ripemd160 $tmpfname"))."\n";
  255. echo "RIPEMD-160: ".splitn(60,openssl("rmd160",$tmpfname))."\n";
  256. #echo "SHA2-256: ".split32(exec("/home/paulscho/bin/sha2-256 $tmpfname"))."\n";
  257. #echo "SHA2-384: ".split32(exec("/home/paulscho/bin/sha2-384 $tmpfname"))."\n";
  258. #echo "SHA2-512: ".split32(exec("/home/paulscho/bin/sha2-512 $tmpfname"))."\n";
  259. unlink($tmpfname);
  260.  
  261. function openssl($dgst = "sha1", $filename) {
  262. $sha1 = explode("= ",exec("/usr/bin/openssl dgst -$dgst $filename"));
  263. return trim($sha1[1]);
  264. }
  265.  
  266. ?></textarea>
  267. <br>
  268. (This cannot be decoded<sup>*</sup>)
  269. </td></tr></form></table>
  270.  
  271. <?
  272. function split32($text) {
  273.     $string = "";
  274.     for($i = 0; $i < strlen($text); $i = $i + 32) {
  275.         $string = "$string\n  ".substr($text, $i, 32);
  276.     }
  277.     return $string;
  278. }
  279. function splitn($n,$text) {
  280.     $string = "";
  281.     for($i = 0; $i < strlen($text); $i = $i + $n) {
  282.         $string = "$string\n  ".substr($text, $i, $n);
  283.     }
  284.     return $string;
  285. }
  286. ?>
  287. </body>
  288. </html>
Add Comment
Please, Sign In to add comment