Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = readline();
- $pattern = '/^(?<artistName>[A-Z][a-z\' ]+):(?<songName>[A-Z ]+)$/';
- $lowLetters = range("a", "z");
- $highLetters = range("A","Z");
- while ($input !== "end") {
- if (preg_match($pattern, $input)) {
- list($artist, $songName) = explode(":", $input);
- $encKey = strlen($artist);
- for ($i = 0; $i < strlen($input);$i++){
- $checker = 0;
- if ($input[$i] !== " " && $input[$i] !== "'") {
- if ($input[$i] === ":") {
- $input[$i] = "@";
- continue;
- }
- $currLetterAscii = ord($input[$i]);
- $checker = $currLetterAscii + $encKey;
- if (in_array($input[$i], $lowLetters)) {
- $resUpper = 0;
- if ($checker > 122) {
- $resUpper = $checker - 122;
- $input[$i] = chr(97 + $resUpper - 1);
- continue;
- }
- }
- if (in_array($input[$i], $highLetters)) {
- $resSmall = 0;
- if ($checker > 90) {
- $resSmall = $checker - 90;
- $input[$i] = chr(65 + $resSmall - 1);
- continue;
- }
- }
- $input[$i] = chr($currLetterAscii + $encKey);
- }
- }
- echo "Successful encryption: $input" . PHP_EOL;
- } else {
- echo "Invalid input!" . PHP_EOL;
- }
- $input = readline();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement