SHARE
TWEET

Fixed Song Decrypt

MartinGeorgiev Dec 16th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //$re = '/^[A-Z][a-z]*\s?[a-z]*:[A-Z\s]*$/m';
  3. $re = '/^[A-Z][a-z\'\]*\s?[a-z]*:[A-Z\s]*$/m';
  4. $input = readline();
  5. $match = "";
  6. $whitespace =  '/\s/m';
  7. while (true) {
  8.     if ($input=="end"){
  9.         break;
  10.     }
  11.     if (preg_match($re, $input, $match)) {
  12.         $tokens = explode(":", $input);
  13.         $artist = $tokens[0];
  14.         $song = $tokens[1];
  15.         $decrypt = "";
  16.         $key = strlen($artist);
  17.         for ($i = 0; $i < strlen($input); $i++) {
  18.             $current = $input[$i];
  19.             if (preg_match($whitespace, $current, $match)||$current=="'") {
  20.                 $decrypt .= $current;
  21.                 continue;
  22.  
  23.             }else if($current==":"){
  24.                 $decrypt .= "@";
  25.                 continue;
  26.             }
  27.             else if (ord($current) + $key > 90 && ctype_upper($current)) {
  28.  
  29.                 $decrypt .= chr(ord($current) + $key-26);
  30.             } else if (ord($current) + $key > 122 && ctype_lower($current)) {
  31.                 $decrypt .= chr(ord($current) + $key-26);
  32.             } else {
  33.                 $decrypt .= chr(ord($current) + $key);
  34.             }
  35.  
  36.         }
  37.         echo "Successful encryption: $decrypt". PHP_EOL;
  38.  
  39.  
  40.     } else {
  41.         echo "Invalid input!".PHP_EOL;
  42.     }
  43.     $input = readline();
  44.  
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top