sneak.php

  1. <?php
  2.  /***********************************************************************
  3.  * sneak.php - v 1.27 - 2003/02/12
  4.  *
  5.  * SNEAK: Snarkles.Net Encryption Assortment Kit
  6.  * =============================================
  7.  * Send and decode messages using a number of different methods
  8.  *
  9.  * Please forward any suggestions, problems, improvements, etc. to the 
  10.  * e-mail address below. Thanks! :D
  11.  *
  12.  * Copyright (c) 2000 - 2004 snarkles ([email protected])
  13.  * Distributed under the GNU/GPL license (see http://www.gnu.org/copyleft/)
  14.  * URL@    z4.cn
  15.  ************************************************************************/
  16.  /************************************************************************
  17.  * Changelog
  18.  * =========
  19.  * v 1.27 - 2004/10/28:
  20.  * - Added zero padding to hex conversions < 10. Thanks to bubuche93 for
  21.  *   the heads up.
  22.  *
  23.  * v 1.26 - 2003/06/20:
  24.  * - Added function strip_spaces to remove spaces prior to trying to
  25.  *   base64 decode a string. Thanks for Jeian and Goldfish for pointing
  26.  *   this out.
  27.  *   
  28.  * v 1.25 - 2003/02/12:
  29.  * - Fixed a bug in form that initially displayed an error about an 
  30.  *   undefined variable in the textbox if error_reporting is set to max. 
  31.  *   Thanks to Justin Hagstrom for notifying me of the problem. :)
  32.  *
  33.  * v 1.24 - 2003/02/01:
  34.  * - D'oh! Fixed a bug I introduced with the Caesar Bruteforce option that
  35.  *   stuck that XSS vulnerability right back in there! :P
  36.  *
  37.  * v 1.23 - 2003/01/27:
  38.  * - Added "Caesar Bruteforce" option which will attempt all 26 
  39.  *   possible shifts of a Caesar (rotation) cipher.
  40.  *
  41.  * v 1.22 - 2003/01/26:
  42.  * - Textbox now retains original text value, so you can try different 
  43.  *   encryption methods on the same text without copying/pasting
  44.  *   Thanks to barnseyboy who suggested the feature. :)
  45.  *
  46.  * v 1.21 - 2003/01/14:
  47.  * - Fixed XSS vulnerability that could potentially allow people to steal
  48.  *   cookies from sites with the script installed.
  49.  *   Credit for spotting this vulnerability goes to JeiAr from
  50.  *   CyberArmy Security Research (http://www.security-research.org/)
  51.  *
  52.  * v 1.20 - 2002/08/10:
  53.  * - Added HTML entity encode/decode option
  54.  * - Changed order of listings so encoding is always before decoding
  55.  * - Fixed problem that caused special characters to be lost when 
  56.  *   writing back to the screen
  57.  *
  58.  * v 1.11 - 2002/02/21:
  59.  * - Cleaned up code some--now all chunk_splitting and str_replacing is 
  60.  *   done within the functions, rather than during the switch statement
  61.  * - Specified CRYPT_STD_DES in crypt() function, to fix problem with PHP 4.1.2
  62.  *
  63.  * v 1.10 - 2002/02/17:
  64.  * - Added bin2hex, hex2bin, and pig latin functions
  65.  *
  66.  * v 1.00 - 2002/02/15:
  67.  * - Nothing yet, but I'm sure that'll CHANGE. Ha! Get it? ;)
  68.  *************************************************************************/
  69. $version = "1.27";
  70. // You can alter the HTML below to make this script fit more inline with 
  71. // the rest of your site.
  72. ?>
  73. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  74. <html>
  75. <head>
  76.     <title>SNEAK: Snarkles.Net Encryption Assortment Kit</title>
  77.     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  78.     <style type="text/css">
  79.     <!--
  80.         body { font-family: "arial", "helvetica", sans-serif; font-size: 10pt; }
  81.     -->
  82.     </style>
  83. </head>
  84. <body>
  85. <?php
  86. // Declare some functions for encryption not included in PHP
  87. function asc2bin($str) {
  88.     $text_array = explode("/r/n", chunk_split($str, 1));
  89.     for ($n = 0; $n < count($text_array) - 1; $n++) {
  90.         $newstring .= substr("0000".base_convert(ord($text_array[$n]), 10, 2), -8);
  91.     }
  92.     $newstring = chunk_split($newstring, 8, " ");
  93.     return $newstring;
  94. }
  95. function bin2asc($str) {
  96.     $str = str_replace(" ", "", $str);
  97.     $text_array = explode("/r/n", chunk_split($str, 8));
  98.     for ($n = 0; $n < count($text_array) - 1; $n++) {
  99.         $newstring .= chr(base_convert($text_array[$n], 2, 10));
  100.     }
  101.     return $newstring;
  102. }
  103. // Made this alias because "bin2hex" would be confusing in the context of this script :P
  104. function asc2hex($str) {
  105.     return chunk_split(bin2hex($str), 2, " ");
  106. }
  107. function hex2asc($str) {
  108.     $str = str_replace(" ", "", $str);
  109.     for ($n=0; $n<strlen($str); $n+=2) {
  110.         $newstring .=  pack("C", hexdec(substr($str, $n, 2)));
  111.     }
  112.     return $newstring;
  113. }
  114. function binary2hex($str) {
  115.     $str = str_replace(" ", "", $str);
  116.     $text_array = explode("/r/n", chunk_split($str, 8));
  117.     for ($n = 0; $n < count($text_array) - 1; $n++) {
  118.         $newstring .= str_pad(base_convert($text_array[$n], 2, 16), 2, "0", STR_PAD_LEFT);
  119.     }
  120.     $newstring = chunk_split($newstring, 2, " ");
  121.     return $newstring;
  122. }
  123. function hex2binary($str) {
  124.     $str = str_replace(" ", "", $str);
  125.     $text_array = explode("/r/n", chunk_split($str, 2));
  126.     for ($n = 0; $n < count($text_array) - 1; $n++) {
  127.         $newstring .= substr("0000".base_convert($text_array[$n], 16, 2), -8);
  128.     }
  129.     $newstring = chunk_split($newstring, 8, " ");
  130.     return $newstring;
  131. }
  132. function caesarbf($str) {
  133.     $alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  134.     echo "<table width=/"85%/" cellpadding=/"2/" align=/"center/">/n";
  135.     for ($n = 1; $n < 26; $n++) {
  136.         $cipher = substr($alpha, $n, 26 - $n) . substr($alpha, 0, $n) . substr($alpha, 26+$n, 52-$n) . substr($alpha, 26, $n);
  137.         if ($n % 2 == 0) {
  138.             echo '<tr bgcolor="#eeeeee">';
  139.         } else {
  140.             echo '<tr bgcolor="#cccccc">';
  141.         }
  142.         echo "<td>ROT-$n". strtr($str, $alpha, $cipher) ."</td>";
  143.     }
  144.     echo "<tr>/n";
  145.     echo "</table>/n";
  146. }
  147. function entityenc($str) {
  148.     $text_array = explode("/r/n", chunk_split($str, 1));
  149.     for ($n = 0; $n < count($text_array) - 1; $n++) {
  150.         $newstring .= "&#" . ord($text_array[$n]) . ";";
  151.     }
  152.     return $newstring;
  153. }
  154. function entitydec($str) {
  155.     $str = str_replace(';', '; ', $str);
  156.     $text_array = explode(' ', $str);
  157.     for ($n = 0; $n < count($text_array) - 1; $n++) {
  158.         $newstring .= chr(substr($text_array[$n], 2, 3));
  159.     }
  160.     return $newstring;
  161. }
  162. function l33t($str) {
  163.     $from = 'ieastoIEASTO';
  164.     $to = '134570134570';
  165.     $newstring = strtr($str, $from, $to);
  166.     return $newstring;
  167. }
  168. function del33t($str) {
  169.     $from = '134570';
  170.     $to = 'ieasto';
  171.     $newstring = strtr($str, $from, $to);
  172.     return $newstring;
  173. }
  174. function igpay($str) {
  175.     $text_array = explode(" ", $str);
  176.     for ($n = 0; $n < count($text_array); $n++) {
  177.         $newstring .= substr($text_array[$n], 1) . substr($text_array[$n], 0, 1) . "ay ";
  178.     }
  179.     return $newstring;
  180. }
  181. function unigpay($str) {
  182.     $text_array = explode(" ", $str);
  183.     for ($n = 0; $n < count($text_array); $n++) {
  184.         $newstring .= substr($text_array[$n], -3, 1) . substr($text_array[$n], 0, strlen($text_array[$n]) - 3) . " ";
  185.     }
  186.     return $newstring;
  187. }
  188. function rot13($str) {
  189.     $from = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  190.     $to   = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
  191.     $newstring = strtr($str, $from, $to);
  192.     return $newstring;
  193. }
  194. function strip_spaces($str) {
  195.     $str = str_replace(" ", "", $str);
  196.     return $str;
  197. }
  198. // Check to see if form has been submitted yet
  199. if(isset($_POST['submit'])) {
  200.     // Yes, so make sure they filled something in
  201.     $text = $_POST['text'];
  202.     if($text == '') {
  203.         die("<p>Fill in the form, dinglefritz! ;)</p>/n");
  204.     }
  205.     // Looks good, so clean up data
  206.     $text = urldecode(stripslashes($text));
  207.     // Make copy of original text for later display
  208.     $orig_text = $text;
  209.     $orig_text = htmlentities($orig_text);
  210.     echo("<p>$orig_text converts to:</p>/n");
  211.     // De/Encrypt based on selection in form
  212.     switch ($_POST['cryptmethod']) {
  213.         case "asc2bin":
  214.             $text = asc2bin($text);
  215.             break;
  216.         case "asc2hex":
  217.             $text = asc2hex($text);
  218.             break;
  219.         case "bin2asc":
  220.             $text = bin2asc($text);
  221.             break;
  222.         case "hex2asc":
  223.             $text = hex2asc($text);
  224.             break;
  225.         case "bin2hex":
  226.             $text = binary2hex($text);
  227.             break;
  228.         case "hex2bin":
  229.             $text = hex2binary($text);
  230.             break;
  231.         case "backwards":
  232.             $text = strrev($text);
  233.             break;
  234.         case 'b64enc':
  235.             $text = base64_encode($text);
  236.             break;
  237.         case 'b64dec':
  238.             $text = base64_decode(strip_spaces($text));
  239.             break;
  240.         case 'caesarbf':
  241.             $text = caesarbf($text);
  242.             break;
  243.         case 'crypt':
  244.             $text = crypt($text, 'CRYPT_STD_DES');
  245.             break;
  246.         case 'entityenc':
  247.             $text = entityenc($text);
  248.             break;
  249.         case 'entitydec':
  250.             $text = entitydec($text);
  251.             break;
  252.         case "l33t":
  253.             $text = l33t($text);
  254.             break;
  255.         case "del33t":
  256.             $text = del33t($text);
  257.             break;
  258.         case 'md5':
  259.             $text = md5($text);
  260.             break;
  261.         case 'igpay':
  262.             $text = igpay($text);
  263.             break;
  264.         case 'unigpay':
  265.             $text = unigpay($text);
  266.             break;
  267.         case "rot-13":
  268.             $text = rot13($text);
  269.             break;
  270.         case 'urlenc':
  271.             $text = urlencode($text);
  272.             break;
  273.         case 'urldec':
  274.             $text = urldecode($text);
  275.             break;
  276.         default:
  277.             die("<p>That encryption type is not supported.</p>/n");
  278.     } // end switch
  279.     // Convert to HTML entities so special chars show up
  280.     $text = htmlentities($text);
  281.     // Display result to the screen
  282.     echo("<p>$text</p>/n");
  283. } // end if
  284. ?>
  285. <!-- begin form -->
  286. <center>
  287. <form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
  288.     <textarea name="text" rows="5" cols="50"><?php if (isset($orig_text)) { echo($orig_text); } ?></textarea><br />
  289.     <select name="cryptmethod">
  290.     <option value="asc2bin">ASCII to Binary</option>
  291.     <option value="bin2asc">Binary to ASCII</option>
  292.     <option value="asc2hex">ASCII to Hex</option>
  293.     <option value="hex2asc">Hex to ASCII</option>
  294.     <option value="bin2hex">Binary to Hex</option>
  295.     <option value="hex2bin">Hex to Binary</option>
  296.     <option value="backwards">Backwards</option>
  297.     <option value="b64enc">Base 64 Encode</option>
  298.     <option value="b64dec">Base 64 Decode</option>
  299.     <option value="caesarbf">Caesar Bruteforce</option>
  300.     <option value="crypt">DES Crypt (one way)</option>
  301.     <option value="entityenc">HTML Entities Encode</option>
  302.     <option value="entitydec">HTML Entities Decode</option>
  303.     <option value="l33t">l33t 5p34k 3nc0d3</option>
  304.     <option value="del33t">l33t 5p34k d3c0d3</option>
  305.     <option value="md5">MD5 Crypt (one way)</option>
  306.     <option value="igpay">Igpay Atinlay</option>
  307.     <option value="unigpay">Un-Pig Latin</option>
  308.     <option value="rot-13">ROT-13</option>
  309.     <option value="urlenc">URL Encode</option>
  310.     <option value="urldec">URL Decode</option>
  311.     </select><br />
  312.     <input type="submit" name="submit" value="OK" />
  313.     <input type="reset" value="Clear" />
  314. </form>
  315. </center>
  316. <!-- end form -->
  317. <!-- begin footer; it would be nice if you would leave this on. ;) -->
  318. <center>
  319. <p>
  320.     <font size="1">Fine Print Shtuff:<br />
  321.     SNEAK: Snarkles.Net Encryption Assortment Kit - Version <?php echo($version); ?><br />
  322.     &copy; 2000, 2001, 2002, 2003 <a href="http://snarkles.net">snarkles</a><br />
  323.     Download a copy <a href="http://snarkles.net/scripts/sneak/sneak-<?php echo($version); ?>.zip">here</a></font>
  324. </p>
  325. </center>
  326. <!-- end footer -->
  327. </body>
  328. </html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章