Advertisement
MartinGeorgiev

Song Decrypt

Dec 16th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement