leongrdic

Lecrypt v0.4

Feb 20th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.23 KB | None | 0 0
  1. <?php
  2. // All Rights Reserved, Leon Grdic (ImTheLe), 2016
  3. // I do no reccommend using this for production purposes
  4. // If you manage to break the encryption, please contact me on imthele.com
  5.  
  6. $symbols = [
  7.     '0' => 735, '1' => 236, '2' => 527, '3' => 413, '4' => 264,
  8.     '5' => 638, '6' => 694, '7' => 103, '8' => 977, '9' => 812,
  9.     'A' => 487, 'B' => 349, 'C' => 823, 'D' => 541, 'E' => 210,
  10.     'F' => 468, 'G' => 112, 'H' => 348, 'I' => 621, 'J' => 901,
  11.     'K' => 122, 'L' => 314, 'M' => 952, 'N' => 641, 'O' => 458,
  12.     'P' => 639, 'Q' => 686, 'R' => 599, 'S' => 467, 'T' => 289,
  13.     'U' => 318, 'V' => 415, 'W' => 512, 'X' => 286, 'Y' => 350,
  14.     'Z' => 872, 'a' => 465, 'b' => 910, 'c' => 100, 'd' => 120,
  15.     'e' => 102, 'f' => 397, 'g' => 689, 'h' => 704,  'i' => 225,
  16.     'j' => 117, 'k' => 989, 'l' => 666, 'm' => 999, 'n' => 787,
  17.     'o' => 699, 'p' => 974, 'q' => 969, 'r' => 979, 's' => 555,
  18.     't' => 471, 'u' => 376, 'v' => 625, 'w' => 591, 'x' => 986,
  19.     'y' => 137, 'z' => 307, '.' => 357, ',' => 472, ':' => 849,
  20.     ';' => 595, '(' => 833, ')' => 111, '[' => 190, ']' => 309,
  21.     '{' => 547, '}' => 293, '|' => 412, '/' => 531, '\\' => 650,
  22.     '@' => 769, '-' => 515, '_' => 753, '+' => 994, '<' => 991,
  23.     '>' => 110, '=' => 229, '~' => 975, '!' => 473, '?' => 213,
  24.     '&' => 332, '#' => 115, '^' => 931, '"' => 550, '\'' => 875,
  25.     '$' => 691, '%' => 390, '*' => 791, '`' => 310, ' ' => 623,
  26.     "\n" => 273, "\r" => 742, "\t" => 850
  27. ];
  28.  
  29. function encrypt($phrase, $key = '', $raw = 0){
  30.     global $symbols;
  31.    
  32.     $keyval = 0;
  33.     for($i = 0; $i < strlen($key); $i++){
  34.         $keyval += $symbols[$key[$i]];
  35.     }
  36.     $keyval *= strlen($key);
  37.    
  38.     $comb = '';
  39.     $j = 0;
  40.     for($i = 0; $i < strlen($phrase); $i++){
  41.         $comb .= abs($keyval*$symbols[$key[$j]]*($j+1)*(!$i ? 1 : $symbols[$phrase[($i-1)]]) - $symbols[$phrase[$i]]*($i+1));
  42.         if($j++ == strlen($key)-1) $j = 0;
  43.     }
  44.    
  45.     if(!$raw){
  46.         $trancomb = '';
  47.         while($comb != ''){
  48.             $tmp = array_search(substr($comb, 0, 3), $symbols);
  49.             if(!is_numeric($tmp) && $tmp){
  50.                 $trancomb .= $tmp;
  51.                 $comb = substr($comb, 3, strlen($comb)-3);
  52.             }else{
  53.                 $trancomb .= substr($comb, 0, 1);
  54.                 $comb = substr($comb, 1, strlen($comb)-1);
  55.             }
  56.         }
  57.         return $trancomb;
  58.     }else{
  59.         return $comb;
  60.     }
  61. }
  62.  
  63. function decrypt($trancomb, $key = '', $raw = 0){
  64.     global $symbols;
  65.    
  66.     if(!$raw){
  67.         $comb = '';
  68.         while($trancomb != ''){
  69.             $tmp = $trancomb[0];
  70.             if(!is_numeric($tmp)){
  71.                 $comb .= $symbols[$tmp];
  72.             }else{
  73.                 $comb .= $tmp;
  74.             }
  75.             $trancomb = substr($trancomb, 1, strlen($trancomb)-1);
  76.         }
  77.     }else{
  78.         $comb = $trancomb;
  79.     }
  80.    
  81.     $keyval = 0;
  82.     for($i = 0; $i < strlen($key); $i++){
  83.         $keyval += $symbols[$key[$i]];
  84.     }
  85.     $keyval *= strlen($key);
  86.    
  87.     $phrase = '';
  88.     $e = 1;
  89.     $i = 0;
  90.     $j = 0;
  91.    
  92.     while($comb != ''){
  93.         $tcomb = substr($comb, 0, $e);
  94.         $tphrase = abs($keyval*$symbols[$key[$j]]*($j+1)*(!$i ? 1 : $symbols[$phrase[($i-1)]]) - $tcomb);
  95.         $tphrase /= $i+1;
  96.         $tphrase = array_search($tphrase, $symbols);
  97.         if($tphrase !== FALSE){
  98.             $i++;
  99.             if($j++ == strlen($key)-1) $j = 0;
  100.             $phrase .= $tphrase;
  101.             $comb = substr($comb, $e);
  102.             $e = 1;
  103.         }else{
  104.             $e++;
  105.         }
  106.         if($e>strlen($comb) && $comb != '') return NULL;
  107.     }
  108.    
  109.     return $phrase;
  110. }
  111.  
  112. echo "\nLecrypt v0.4\n\n";
  113.  
  114. $options = getopt('h::e:d:k:o:r::');
  115. if(isset($options['h'])){
  116.     echo "Format: php Lecrypt.php [-option \"value\"]\n";
  117.     echo "Options:\n";
  118.     echo "  -h  Display help\n";
  119.     echo "  -e  Sets the action to Encrypt; Specifies the input file\n";
  120.     echo "  -d  Sets the action to Decrypt; Specifies the input file\n";
  121.     echo "  -o  Specifies the output file\n";
  122.     echo "  -k  Specifies the key used for encryption/decryoption (Optional)\n";
  123.     echo "  -r  Enables the raw encryption/decryption mode (Optional)";
  124. }else{
  125.     if(isset($options['e']) && !isset($options['d'])){
  126.         if(isset($options['o'])){
  127.             if(file_exists($options['e'])){
  128.                 file_put_contents($options['o'], '');
  129.                
  130.                 $phrase = file_get_contents($options['e']);
  131.                 $key = (isset($options['k']) ? $options['k'] : '');
  132.                 $raw = (isset($options['r']) ? 1 : 0);
  133.                
  134.                 echo "Action: Encrypt\n";
  135.                 echo "Input file: " . realpath($options['e']) . "\n";
  136.                 echo "Output file: " . realpath($options['o']) . "\n";
  137.                 echo "Key: " . ($key ? (strlen($key) . " chars") : 'empty') . "\n";
  138.                 echo "Input size: " . strlen($phrase) . "\n";
  139.                 echo "Raw mode: " . ($raw ? "On" : "Off") . "\n";
  140.                 echo "Starting...\n\n";
  141.                
  142.                 $timeStart = microtime(true);
  143.                 $phrase_encrypted = encrypt($phrase, $key, $raw);
  144.                 $timeElapsed = microtime(true) - $timeStart;
  145.                
  146.                 file_put_contents($options['o'], $phrase_encrypted);
  147.                
  148.                 echo "Done.\n";
  149.                 echo "Time taken: " . $timeElapsed . " seconds\n";
  150.                 echo "Output size: " . strlen($phrase_encrypted);
  151.             }else{
  152.                 echo "Error: Input file not found.";
  153.             }
  154.         }else{
  155.             echo "Incomplete arguments, use -h for a list of options!";
  156.         }
  157.     }else if(isset($options['d']) && !isset($options['e'])){
  158.         if(isset($options['o'])){
  159.             if(file_exists($options['d'])){
  160.                 file_put_contents($options['o'], '');
  161.                
  162.                 $phrase_encrypted = file_get_contents($options['d']);
  163.                 $key = (isset($options['k']) ? $options['k'] : '');
  164.                 $raw = (isset($options['r']) ? 1 : 0);
  165.                
  166.                 echo "Action: Decrypt\n";
  167.                 echo "Input file: " . realpath($options['d']) . "\n";
  168.                 echo "Output file: " . realpath($options['o']) . "\n";
  169.                 echo "Key: " . ($key ? (strlen($key) . " chars") : 'empty') . "\n";
  170.                 echo "Input size: " . strlen($phrase_encrypted) . "\n";
  171.                 echo "Raw mode: " . ($raw ? "On" : "Off") . "\n";
  172.                 echo "Starting...\n\n";
  173.                
  174.                 $timeStart = microtime(true);
  175.                 $phrase = decrypt($phrase_encrypted, $key, $raw);
  176.                 $timeElapsed = microtime(true) - $timeStart;
  177.                
  178.                 if(!is_null($phrase)){
  179.                     file_put_contents($options['o'], $phrase);
  180.                    
  181.                     echo "Done.\n";
  182.                     echo "Time taken: " . $timeElapsed . " seconds\n";
  183.                     echo "Output size: " . strlen($phrase);
  184.                 }else{
  185.                     unlink($options['o']);
  186.                    
  187.                     echo "Error: Decryption failed.";
  188.                 }
  189.             }else{
  190.                 echo "Error: Input file not found.";
  191.             }
  192.         }else{
  193.             echo "Incomplete arguments, use -h for a list of options!";
  194.         }
  195.     }else{
  196.         echo "Incomplete arguments, use -h for a list of options!";
  197.     }
  198. }
  199.  
  200. echo "\n\nExiting Lecrypt\n";
  201.  
  202. exit;
  203.  
  204. ?>
Advertisement
Add Comment
Please, Sign In to add comment