Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _2_SongEncryption
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string input = "";
  11. Regex regex = new Regex(@"^[A-Z][a-z\' ]+\:[A-Z]+(\s?[A-Z]+)*\b");
  12. while ((input = Console.ReadLine()) != "end")
  13. {
  14. if (regex.IsMatch(input))
  15. {
  16. string[] splitInput = input.Split(":");
  17. string artist = splitInput[0];
  18.  
  19. char[] arrInput = input.ToCharArray();
  20. for (int i = 0; i < arrInput.Length; i++)
  21. {
  22. int key = artist.Length;
  23. if (char.IsLetter(arrInput[i]) && char.IsLower(arrInput[i]))
  24. {
  25. int symbol = arrInput[i];
  26. while (key > 0)
  27. {
  28. symbol++;
  29. key--;
  30. if (symbol == 123)
  31. {
  32. symbol = 97;
  33. }
  34.  
  35. } //counter
  36. arrInput[i] = (char)symbol;
  37. }
  38. else if (char.IsLetter(arrInput[i]) && char.IsUpper(arrInput[i]))
  39. {
  40. int symbol = arrInput[i];
  41. while (key > 0)
  42. {
  43. symbol++;
  44. key--;
  45. if (symbol == 91)
  46. {
  47. symbol = 65;
  48. }
  49.  
  50. } //counter
  51. arrInput[i] = (char)symbol;
  52. }
  53. else if (arrInput[i] == ':')
  54. {
  55. arrInput[i] = '@';
  56. }
  57.  
  58. } // encrypt
  59.  
  60. Console.WriteLine($"Successful encryption: {string.Join("", arrInput)}");
  61. }
  62. else
  63. {
  64. Console.WriteLine("Invalid input!");
  65. }
  66. }
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement