Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _02._Song_Encryption
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string commandLine = string.Empty;
  13. var encryptedArtis = new StringBuilder();
  14. var encryptedSongs = new StringBuilder();
  15. while ((commandLine=Console.ReadLine())!= "end")
  16. {
  17. string[] currentCommnad = commandLine.Split(":").ToArray();
  18. string artist = currentCommnad[0];
  19. string song = currentCommnad[1];
  20. string pattertForArtist = @"^[A-Z][a-z\s']+$";
  21. var artistValid = Regex.Match(artist,pattertForArtist);
  22. string patternForSong = @"^[A-Z\s]+$";
  23. var songValid = Regex.Match(song, patternForSong);
  24. if (!songValid.Success||!artistValid.Success)
  25. {
  26. Console.WriteLine($"Invalid input!");
  27. }
  28. else
  29. {
  30. Console.Write("Successful encryption: ");
  31. for (int i = 0; i < artist.Length; i++)
  32. {
  33. int key = artist.Length;
  34. if (artist[i] == 32)
  35. {
  36. encryptedArtis.Append(" ");
  37. }
  38.  
  39. else if (artist[i] == '\'')
  40. {
  41. encryptedArtis.Append('\'');
  42. }
  43. else if ((char)(artist[i]+key)>'z')
  44. {
  45. int newChar= (artist[i] + key) % 122;
  46. encryptedArtis.Append((char)(96+newChar));
  47. }
  48. else
  49. {
  50. encryptedArtis.Append((char)(artist[i]+key));
  51. }
  52.  
  53. }
  54. encryptedArtis.Append("@");
  55. for (int i = 0; i < song.Length; i++)
  56. {
  57. int key = artist.Length;
  58. if (song[i] == 32)
  59. {
  60. encryptedSongs.Append(" ");
  61. }
  62.  
  63. else if ((char)(song[i] + key) > 90)
  64. {
  65. int newChar = (song[i] + key) % 90;
  66. encryptedSongs.Append((char)(64 + newChar));
  67. }
  68. else if((char)(song[i] + key) < 90)
  69. {
  70. encryptedSongs.Append((char)(song[i] + key));
  71. }
  72. }
  73. Console.Write(encryptedArtis);
  74. Console.Write(encryptedSongs);
  75. encryptedArtis.Clear();
  76. encryptedSongs.Clear();
  77. Console.WriteLine();
  78. }
  79.  
  80. }
  81.  
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement