Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $re = '/^[A-Z][a-z]*\s?[a-z]*:[A-Z\s]*$/m';
- $input = readline();
- $match = "";
- while (true) {
- if ($input=="end"){
- break;
- }
- if (preg_match($re, $input, $match)) {
- $tokens = explode(":", $input);
- $artist = $tokens[0];
- $song = $tokens[1];
- $decrypt = "";
- $key = strlen($artist);
- for ($i = 0; $i < strlen($input); $i++) {
- $current = $input[$i];
- if ($current == " ") {
- $decrypt .= " ";
- continue;
- }else if($current==":"){
- $decrypt .= "@";
- continue;
- }
- else if (ord($current) + $key > 90 && ctype_upper($current)) {
- $decrypt .= chr(65 + $key);
- } else if (ord($current) + $key > 122 && ctype_lower($current)) {
- $decrypt .= chr(97 + $key);
- } else {
- $decrypt .= chr(ord($current) + $key);
- }
- }
- echo "Successful encryption: $decrypt". PHP_EOL;
- } else {
- echo "Invalid input!";
- }
- $input = readline();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement