Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2020
1,882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2. $input = intval(readline());
  3. $regexFirst = '/(^[$|%]{1})([A-Z]{1}[a-z]{2,})([$|%]{1})/';
  4. $regexSecond = '/([^\$%\]\[\|]+)/';
  5. for ($d = 0; $d < $input; $d++) {
  6.     $args = explode(': ', readline());
  7.     $wordFirst = preg_match($regexFirst, $args[0], $matchWord);
  8.     $wordSecond = preg_match_all($regexSecond, $args[1], $matchWordS);
  9.     if (preg_match($regexFirst, $args[0], $matchWord)
  10.         && $matchWord[1] == $matchWord[3] && count($matchWordS[0]) == 3) {
  11.         $tag = $matchWord[2];
  12.         $decryptedMessage = '';
  13.         for ($i = 0; $i < count($matchWordS[0]); $i++) {
  14.             $decryptedMessage .= chr($matchWordS[0][$i]);
  15.         }
  16.         echo "{$tag}: {$decryptedMessage}\n";
  17.  
  18.     } else {
  19.         echo "Valid message not found!" . PHP_EOL;
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement