Advertisement
emotrend

Song ec

Dec 17th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php
  2.  
  3. $input = readline();
  4. $pattern = '/^(?<artistName>[A-Z][a-z\' ]+):(?<songName>[A-Z ]+)$/';
  5. $lowLetters = range("a", "z");
  6. $highLetters = range("A","Z");
  7.  
  8.  
  9. while ($input !== "end") {
  10.  
  11. if (preg_match($pattern, $input)) {
  12. list($artist, $songName) = explode(":", $input);
  13. $encKey = strlen($artist);
  14.  
  15. for ($i = 0; $i < strlen($input);$i++){
  16. $checker = 0;
  17. if ($input[$i] !== " " && $input[$i] !== "'") {
  18. if ($input[$i] === ":") {
  19. $input[$i] = "@";
  20. continue;
  21. }
  22. $currLetterAscii = ord($input[$i]);
  23. $checker = $currLetterAscii + $encKey;
  24.  
  25. if (in_array($input[$i], $lowLetters)) {
  26. $resUpper = 0;
  27. if ($checker > 122) {
  28. $resUpper = $checker - 122;
  29. $input[$i] = chr(97 + $resUpper - 1);
  30. continue;
  31. }
  32. }
  33. if (in_array($input[$i], $highLetters)) {
  34. $resSmall = 0;
  35. if ($checker > 90) {
  36. $resSmall = $checker - 90;
  37. $input[$i] = chr(65 + $resSmall - 1);
  38. continue;
  39. }
  40. }
  41. $input[$i] = chr($currLetterAscii + $encKey);
  42. }
  43. }
  44. echo "Successful encryption: $input" . PHP_EOL;
  45. } else {
  46. echo "Invalid input!" . PHP_EOL;
  47. }
  48. $input = readline();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement