daily pastebin goal
66%
SHARE
TWEET

Song Decrypt

MartinGeorgiev Dec 16th, 2018 81 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. $input = readline();
  4. $match = "";
  5. while (true) {
  6.     if ($input=="end"){
  7.         break;
  8.     }
  9.     if (preg_match($re, $input, $match)) {
  10.         $tokens = explode(":", $input);
  11.         $artist = $tokens[0];
  12.         $song = $tokens[1];
  13.         $decrypt = "";
  14.         $key = strlen($artist);
  15.         for ($i = 0; $i < strlen($input); $i++) {
  16.             $current = $input[$i];
  17.             if ($current == " ") {
  18.                 $decrypt .= " ";
  19.                 continue;
  20.  
  21.             }else if($current==":"){
  22.                 $decrypt .= "@";
  23.                 continue;
  24.             }
  25.             else if (ord($current) + $key > 90 && ctype_upper($current)) {
  26.                 $decrypt .= chr(65 + $key);
  27.             } else if (ord($current) + $key > 122 && ctype_lower($current)) {
  28.                 $decrypt .= chr(97 + $key);
  29.             } else {
  30.                 $decrypt .= chr(ord($current) + $key);
  31.             }
  32.  
  33.         }
  34.         echo "Successful encryption: $decrypt". PHP_EOL;
  35.  
  36.  
  37.     } else {
  38.         echo "Invalid input!";
  39.     }
  40.     $input = readline();
  41.  
  42. }
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