Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace SongEncryption
- {
- class Program
- {
- static void Main(string[] args)
- {
- string artistPattern = @"(^[A-Z ]['a-z ]*$)";
- string songPattern = @"(^[A-Z ]*$)";
- Regex artistReg = new Regex(artistPattern);
- Regex songReg = new Regex(songPattern);
- while (true)
- {
- var tokens = Console.ReadLine().Split(":", StringSplitOptions.RemoveEmptyEntries);
- string artist = tokens[0];
- if (artist == "end")
- {
- break;
- }
- string song = tokens[1];
- Match artistMatch = artistReg.Match(artist);
- Match songMatch = songReg.Match(song);
- if (artistMatch.Success && songMatch.Success)
- {
- int key = artist.Length;
- string newArtist = string.Empty;
- string newSong = string.Empty;
- foreach (var symbol in artist)
- {
- if (char.IsWhiteSpace(symbol) || symbol == '\'')
- {
- newArtist += symbol;
- continue;
- }
- int newChar = symbol + key;
- if (char.IsUpper(symbol))
- {
- if (newChar > 90)
- {
- int temp = 0;
- temp = newChar - 90 - 1;
- newChar = 65 + temp;
- }
- }
- else
- {
- if (newChar > 122)
- {
- int temp = 0;
- temp = newChar - 122 - 1;
- newChar = 97 + temp;
- }
- }
- newArtist += (char)newChar;
- }
- foreach (var symbol in song)
- {
- if (char.IsWhiteSpace(symbol) || symbol == '\'')
- {
- newSong += symbol;
- continue;
- }
- int newChar = symbol + key;
- if (char.IsUpper(symbol))
- {
- if (newChar > 90)
- {
- int temp = 0;
- temp = newChar - 90 - 1;
- newChar = 65 + temp;
- }
- }
- else
- {
- if (newChar > 122)
- {
- int temp = 0;
- temp = newChar - 122 - 1;
- newChar = 97 + temp;
- }
- }
- newSong += (char)newChar;
- }
- Console.WriteLine($"Successful encryption: {newArtist}@{newSong}");
- }
- else
- {
- Console.WriteLine("Invalid input!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement