Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace _02._Song_Encryption
- {
- class Program
- {
- static void Main(string[] args)
- {
- string pattern = @"^([A-Z]{1}[a-z]+([ |']*[a-z]*)*):([A-Z]+( ?[A-Z]?)+)$";
- string input;
- while ((input = Console.ReadLine()) != "end")
- {
- Match match = Regex.Match(input, pattern);
- if (!match.Success)
- {
- Console.WriteLine("Invalid input!");
- }
- else
- {
- int key = match.Groups[1].Length;
- string artist = match.Groups[1].Value;
- StringBuilder matches = new StringBuilder();
- matches.Append(match.Groups[1]);
- matches.Append('@');
- matches.Append(match.Groups[3]);
- StringBuilder encryptedArtistSong = new StringBuilder();
- foreach (char item in matches.ToString())
- {
- if (!(item == ' ' || item == '\'' || item == '@'))
- {
- char newChar = ' ';
- if (char.IsUpper(item) && ((int)item + key) <= 90)
- {
- newChar = (char)((int)item + key);
- }
- else if (char.IsUpper(item) && ((int)item + key) > 90)
- {
- newChar = (char)((int)item + key - 90 + 64);
- }
- else if (char.IsLower(item) && ((int)item + key) <= 122)
- {
- newChar = (char)((int)item + key);
- }
- else if (char.IsLower(item) && ((int)item + key) > 122)
- {
- newChar = (char)((int)item + key - 122 + 96);
- }
- encryptedArtistSong.Append(newChar);
- }
- else
- {
- encryptedArtistSong.Append(item);
- }
- }
- Console.WriteLine($"Successful encryption: {encryptedArtistSong}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement