Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace _02.SongEcryption
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- while (input != "end")
- {
- Regex regex = new Regex(@"^([A-z][a-z' ]+):([A-Z ]+)$");
- Match matches = regex.Match(input);
- if (matches.Success)
- {
- string artist = matches.Groups[1].Value;
- string song = matches.Groups[2].Value;
- string newArtist = "";
- int key = artist.Length;
- int valueArtist;
- int valueSong;
- string newSong = "";
- for (int i = 0; i < key; i++)
- {
- char current = artist[i];
- if (current != ' ' && current != '\'')
- {
- valueArtist = current + key;
- if (char.IsLower(current) && valueArtist > 'z')
- {
- valueArtist = valueArtist - 'z' + ('a' - 1);
- }
- if (char.IsUpper(current) && valueArtist > 'Z')
- {
- valueArtist = valueArtist - 'Z' + ('A' - 1);
- }
- newArtist += (char)valueArtist;
- }
- else
- {
- newArtist += current;
- }
- }
- for (int i = 0; i < song.Length; i++)
- {
- char currentLetter = song[i];
- if (currentLetter != ' ' && currentLetter != '\'')
- {
- valueSong = currentLetter + key;
- if (char.IsLower(currentLetter) && valueSong > 'z')
- {
- valueSong = valueSong - 'z' + ('a' - 1);
- }
- if (char.IsUpper(currentLetter) && valueSong > 'Z')
- {
- valueSong = valueSong - 'Z' + ('A' - 1);
- }
- newSong += (char)valueSong;
- }
- else
- {
- newSong += currentLetter;
- }
- }
- //string password = newArtist + "@" + song;
- Console.WriteLine($"Successful encryption: {newArtist}@{newSong}");
- }
- else
- {
- Console.WriteLine("Invalid input!");
- }
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment