Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace _02._Song_Encryption
- {
- class Program
- {
- static void Main(string[] args)
- {
- string commandLine = string.Empty;
- var encryptedArtis = new StringBuilder();
- var encryptedSongs = new StringBuilder();
- while ((commandLine=Console.ReadLine())!= "end")
- {
- string[] currentCommnad = commandLine.Split(":").ToArray();
- string artist = currentCommnad[0];
- string song = currentCommnad[1];
- string pattertForArtist = @"^[A-Z][a-z\s']+$";
- var artistValid = Regex.Match(artist,pattertForArtist);
- string patternForSong = @"^[A-Z\s]+$";
- var songValid = Regex.Match(song, patternForSong);
- if (!songValid.Success||!artistValid.Success)
- {
- Console.WriteLine($"Invalid input!");
- }
- else
- {
- Console.Write("Successful encryption: ");
- for (int i = 0; i < artist.Length; i++)
- {
- int key = artist.Length;
- if (artist[i] == 32)
- {
- encryptedArtis.Append(" ");
- }
- else if (artist[i] == '\'')
- {
- encryptedArtis.Append('\'');
- }
- else if ((char)(artist[i]+key)>'z')
- {
- int newChar= (artist[i] + key) % 122;
- encryptedArtis.Append((char)(96+newChar));
- }
- else
- {
- encryptedArtis.Append((char)(artist[i]+key));
- }
- }
- encryptedArtis.Append("@");
- for (int i = 0; i < song.Length; i++)
- {
- int key = artist.Length;
- if (song[i] == 32)
- {
- encryptedSongs.Append(" ");
- }
- else if ((char)(song[i] + key) > 90)
- {
- int newChar = (song[i] + key) % 90;
- encryptedSongs.Append((char)(64 + newChar));
- }
- else if((char)(song[i] + key) < 90)
- {
- encryptedSongs.Append((char)(song[i] + key));
- }
- }
- Console.Write(encryptedArtis);
- Console.Write(encryptedSongs);
- encryptedArtis.Clear();
- encryptedSongs.Clear();
- Console.WriteLine();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement