Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 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. string encript = string.Empty;
  19.  
  20. char[] arrInput = input.ToCharArray();
  21. for (int i = 0; i < arrInput.Length; i++)
  22. {
  23. int key = artist.Length;
  24. char newSymbol = arrInput[i];
  25. if (arrInput[i] != ' ' && arrInput[i] != '\'')
  26. {
  27. if (char.IsLetter(arrInput[i]) && char.IsLower(arrInput[i]))
  28. {
  29. int symbol = arrInput[i];
  30. while (key > 0)
  31. {
  32. symbol++;
  33. key--;
  34. if (symbol == 123)
  35. {
  36. symbol = 97;
  37. }
  38.  
  39. } //counter
  40. newSymbol = (char)symbol;
  41. }
  42. else if (char.IsLetter(arrInput[i]) && char.IsUpper(arrInput[i]))
  43. {
  44. int symbol = arrInput[i];
  45. while (key > 0)
  46. {
  47. symbol++;
  48. key--;
  49. if (symbol == 91)
  50. {
  51. symbol = 65;
  52. }
  53.  
  54. } //counter
  55. newSymbol = (char)symbol;
  56. }
  57. else if (arrInput[i] == ':')
  58. {
  59. newSymbol = '@';
  60. }
  61. } // encrypt
  62. encript += newSymbol;
  63. }
  64. Console.WriteLine($"Successful encryption: {encript}");
  65. }
  66. else
  67. {
  68. Console.WriteLine("Invalid input!");
  69. }
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement