Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // All Rights Reserved, Leon Grdic (ImTheLe), 2016
- // I do no reccommend using this for production purposes
- // If you manage to break the encryption, please contact me on imthele.com
- $symbols = [
- '0' => 735, '1' => 236, '2' => 527, '3' => 413, '4' => 264,
- '5' => 638, '6' => 694, '7' => 103, '8' => 977, '9' => 812,
- 'A' => 487, 'B' => 349, 'C' => 823, 'D' => 541, 'E' => 210,
- 'F' => 468, 'G' => 112, 'H' => 348, 'I' => 621, 'J' => 901,
- 'K' => 122, 'L' => 314, 'M' => 952, 'N' => 641, 'O' => 458,
- 'P' => 639, 'Q' => 686, 'R' => 599, 'S' => 467, 'T' => 289,
- 'U' => 318, 'V' => 415, 'W' => 512, 'X' => 286, 'Y' => 350,
- 'Z' => 872, 'a' => 465, 'b' => 910, 'c' => 100, 'd' => 120,
- 'e' => 102, 'f' => 397, 'g' => 689, 'h' => 704, 'i' => 225,
- 'j' => 117, 'k' => 989, 'l' => 666, 'm' => 999, 'n' => 787,
- 'o' => 699, 'p' => 974, 'q' => 969, 'r' => 979, 's' => 555,
- 't' => 471, 'u' => 376, 'v' => 625, 'w' => 591, 'x' => 986,
- 'y' => 137, 'z' => 307, '.' => 357, ',' => 472, ':' => 849,
- ';' => 595, '(' => 833, ')' => 111, '[' => 190, ']' => 309,
- '{' => 547, '}' => 293, '|' => 412, '/' => 531, '\\' => 650,
- '@' => 769, '-' => 515, '_' => 753, '+' => 994, '<' => 991,
- '>' => 110, '=' => 229, '~' => 975, '!' => 473, '?' => 213,
- '&' => 332, '#' => 115, '^' => 931, '"' => 550, '\'' => 875,
- '$' => 691, '%' => 390, '*' => 791, '`' => 310, ' ' => 623,
- "\n" => 273, "\r" => 742, "\t" => 850
- ];
- function encrypt($phrase, $key = '', $raw = 0){
- global $symbols;
- $keyval = 0;
- for($i = 0; $i < strlen($key); $i++){
- $keyval += $symbols[$key[$i]];
- }
- $keyval *= strlen($key);
- $comb = '';
- $j = 0;
- for($i = 0; $i < strlen($phrase); $i++){
- $comb .= abs($keyval*$symbols[$key[$j]]*($j+1)*(!$i ? 1 : $symbols[$phrase[($i-1)]]) - $symbols[$phrase[$i]]*($i+1));
- if($j++ == strlen($key)-1) $j = 0;
- }
- if(!$raw){
- $trancomb = '';
- while($comb != ''){
- $tmp = array_search(substr($comb, 0, 3), $symbols);
- if(!is_numeric($tmp) && $tmp){
- $trancomb .= $tmp;
- $comb = substr($comb, 3, strlen($comb)-3);
- }else{
- $trancomb .= substr($comb, 0, 1);
- $comb = substr($comb, 1, strlen($comb)-1);
- }
- }
- return $trancomb;
- }else{
- return $comb;
- }
- }
- function decrypt($trancomb, $key = '', $raw = 0){
- global $symbols;
- if(!$raw){
- $comb = '';
- while($trancomb != ''){
- $tmp = $trancomb[0];
- if(!is_numeric($tmp)){
- $comb .= $symbols[$tmp];
- }else{
- $comb .= $tmp;
- }
- $trancomb = substr($trancomb, 1, strlen($trancomb)-1);
- }
- }else{
- $comb = $trancomb;
- }
- $keyval = 0;
- for($i = 0; $i < strlen($key); $i++){
- $keyval += $symbols[$key[$i]];
- }
- $keyval *= strlen($key);
- $phrase = '';
- $e = 1;
- $i = 0;
- $j = 0;
- while($comb != ''){
- $tcomb = substr($comb, 0, $e);
- $tphrase = abs($keyval*$symbols[$key[$j]]*($j+1)*(!$i ? 1 : $symbols[$phrase[($i-1)]]) - $tcomb);
- $tphrase /= $i+1;
- $tphrase = array_search($tphrase, $symbols);
- if($tphrase !== FALSE){
- $i++;
- if($j++ == strlen($key)-1) $j = 0;
- $phrase .= $tphrase;
- $comb = substr($comb, $e);
- $e = 1;
- }else{
- $e++;
- }
- if($e>strlen($comb) && $comb != '') return NULL;
- }
- return $phrase;
- }
- echo "\nLecrypt v0.4\n\n";
- $options = getopt('h::e:d:k:o:r::');
- if(isset($options['h'])){
- echo "Format: php Lecrypt.php [-option \"value\"]\n";
- echo "Options:\n";
- echo " -h Display help\n";
- echo " -e Sets the action to Encrypt; Specifies the input file\n";
- echo " -d Sets the action to Decrypt; Specifies the input file\n";
- echo " -o Specifies the output file\n";
- echo " -k Specifies the key used for encryption/decryoption (Optional)\n";
- echo " -r Enables the raw encryption/decryption mode (Optional)";
- }else{
- if(isset($options['e']) && !isset($options['d'])){
- if(isset($options['o'])){
- if(file_exists($options['e'])){
- file_put_contents($options['o'], '');
- $phrase = file_get_contents($options['e']);
- $key = (isset($options['k']) ? $options['k'] : '');
- $raw = (isset($options['r']) ? 1 : 0);
- echo "Action: Encrypt\n";
- echo "Input file: " . realpath($options['e']) . "\n";
- echo "Output file: " . realpath($options['o']) . "\n";
- echo "Key: " . ($key ? (strlen($key) . " chars") : 'empty') . "\n";
- echo "Input size: " . strlen($phrase) . "\n";
- echo "Raw mode: " . ($raw ? "On" : "Off") . "\n";
- echo "Starting...\n\n";
- $timeStart = microtime(true);
- $phrase_encrypted = encrypt($phrase, $key, $raw);
- $timeElapsed = microtime(true) - $timeStart;
- file_put_contents($options['o'], $phrase_encrypted);
- echo "Done.\n";
- echo "Time taken: " . $timeElapsed . " seconds\n";
- echo "Output size: " . strlen($phrase_encrypted);
- }else{
- echo "Error: Input file not found.";
- }
- }else{
- echo "Incomplete arguments, use -h for a list of options!";
- }
- }else if(isset($options['d']) && !isset($options['e'])){
- if(isset($options['o'])){
- if(file_exists($options['d'])){
- file_put_contents($options['o'], '');
- $phrase_encrypted = file_get_contents($options['d']);
- $key = (isset($options['k']) ? $options['k'] : '');
- $raw = (isset($options['r']) ? 1 : 0);
- echo "Action: Decrypt\n";
- echo "Input file: " . realpath($options['d']) . "\n";
- echo "Output file: " . realpath($options['o']) . "\n";
- echo "Key: " . ($key ? (strlen($key) . " chars") : 'empty') . "\n";
- echo "Input size: " . strlen($phrase_encrypted) . "\n";
- echo "Raw mode: " . ($raw ? "On" : "Off") . "\n";
- echo "Starting...\n\n";
- $timeStart = microtime(true);
- $phrase = decrypt($phrase_encrypted, $key, $raw);
- $timeElapsed = microtime(true) - $timeStart;
- if(!is_null($phrase)){
- file_put_contents($options['o'], $phrase);
- echo "Done.\n";
- echo "Time taken: " . $timeElapsed . " seconds\n";
- echo "Output size: " . strlen($phrase);
- }else{
- unlink($options['o']);
- echo "Error: Decryption failed.";
- }
- }else{
- echo "Error: Input file not found.";
- }
- }else{
- echo "Incomplete arguments, use -h for a list of options!";
- }
- }else{
- echo "Incomplete arguments, use -h for a list of options!";
- }
- }
- echo "\n\nExiting Lecrypt\n";
- exit;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment