ItsMeStevieG

index.php

May 2nd, 2022 (edited)
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.75 KB | None | 0 0
  1. <?php
  2. session_id("cryptor");
  3. session_start();
  4. class Cryptor
  5. {
  6.     private $B64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\=";
  7.  
  8.     public function genKey()
  9.     {
  10.         return str_shuffle($this->B64Chars);
  11.     }
  12.  
  13.     public function doEncode($src, $key)
  14.     {
  15.         $src=@strrev(@strtr(@base64_encode(@gzdeflate($src, 9)), $this->B64Chars, $key));
  16.  
  17.         return $src;
  18.     }
  19.  
  20.     public function doDecode($src, $key)
  21.     {
  22.         $src=@gzinflate(@base64_decode(@strtr(@strrev($src), $key, $this->B64Chars)));
  23.  
  24.         return $src;
  25.     }
  26. }
  27. $c = new Cryptor();
  28.  
  29. if (isset($_POST) && !empty($_POST)) {
  30.     if (isset($_GET['nav']) && $_GET['nav']=="encode") {
  31.         $enctext = $c->doEncode($_POST['plaintext'], $_POST['key']);
  32.         die("<a href='javascript:history.back();' class='btnLink'>&lt; Back</a><br /><strong>Encoded Text:</strong><br /><textarea style='width: 100%;'>$enctext</textarea>");
  33.     } elseif (isset($_GET['nav']) && $_GET['nav']=="decode") {
  34.         $dectext = $c->doDecode($_POST['encodedtext'], $_POST['key']);
  35.         die("<a href='javascript:history.back();' class='btnLink'>&lt; Back</a><br /><strong>Decoded Text:</strong><br /><textarea style='width: 100%;'>$dectext</textarea>");
  36.     }
  37. }
  38. ?>
  39. <!DOCTYPE html>
  40. <html lang="en">
  41.  
  42. <head>
  43.     <meta charset="UTF-8">
  44.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  45.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  46.     <title>Cryptor</title>
  47.     <style>
  48.         body {
  49.             font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  50.         }
  51.  
  52.         textarea {
  53.             width: 100%;
  54.         }
  55.  
  56.         input[type='text'] {
  57.             width: 100%;
  58.         }
  59.  
  60.         input[type='submit'] {
  61.             margin-top: 5px;
  62.         }
  63.  
  64.         a.btnLink {
  65.             padding: 3px 7px 3px 7px;
  66.             background-color: #06c;
  67.             color: white;
  68.             text-decoration: none;
  69.             ;
  70.             -webkit-border-radius: 5px;
  71.             -moz-border-radius: 5px;
  72.             border-radius: 5px;
  73.         }
  74.  
  75.         a.btnLink:hover {
  76.             text-decoration: underline;
  77.         }
  78.     </style>
  79. </head>
  80.  
  81. <body>
  82.     <a href='?nav=encode' class='btnLink'>Encode</a>&nbsp;&nbsp;&nbsp;<a href='?nav=decode'
  83.         class='btnLink'>Decode</a>&nbsp;&nbsp;&nbsp;<a href='?nav=generate' class='btnLink'>Generate Key</a><br /><br />
  84.     <?php
  85.     if (isset($_GET['nav']) && $_GET['nav']=='encode') {
  86.         if (isset($_SESSION['key'])) {
  87.             $key = $_SESSION['key'];
  88.         } else {
  89.             $key="";
  90.         }
  91.         echo('<form method="POST" action="">
  92.            <strong>Plain Text:</strong><br />
  93.            <textarea name="plaintext"></textarea><br />
  94.            <strong>Key:</strong><br />
  95.            <input name="key" type="text" value="'.$key.'" /><br />
  96.            <input name="submitbtn" value="Encode" type="submit" />
  97.        </form>');
  98.     } elseif (isset($_GET['nav']) && $_GET['nav']=='decode') {
  99.         if (isset($_SESSION['key'])) {
  100.             $key = $_SESSION['key'];
  101.         } else {
  102.             $key="";
  103.         }
  104.         echo('<form method="POST" action="">
  105.            <strong>Encoded Text:</strong><br />
  106.            <textarea name="encodedtext"></textarea><br />
  107.            <strong>Key:</strong><br />
  108.            <input name="key" type="text" value="'.$key.'" /><br />
  109.            <input name="submitbtn" value="Decode" type="submit" />
  110.        </form>');
  111.     } elseif (isset($_GET['nav']) && $_GET['nav']=='generate') {
  112.         $_SESSION['key']=$c->genKey();
  113.         echo($_SESSION['key']);
  114.     }
  115.     ?>
  116.     <br /><small><i>Version: 1.0.0</i></small>
  117. </body>
  118.  
  119. </html>
Add Comment
Please, Sign In to add comment