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 pattern = @"(^[A-Z]{1}[a-z]+[\s|'a-z]*):([A-Z\s*]+\b)";
- string pattern = @"^([A-Z]{1}[a-z\' ]+):([A-Z ]+)\b";
- string input = Console.ReadLine();
- string result = string.Empty;
- while (input != "end")
- {
- Match singerAndSong = Regex.Match(input, pattern);
- if (singerAndSong.Success)
- {
- int key = singerAndSong.Groups["1"].Value.Length;
- string song = singerAndSong.Groups["2"].Value;
- input = input.Replace(":", "@");
- for (int i = 0; i < input.Length; i++)
- {
- char currentChar = input[i];
- if (currentChar != ' ' && currentChar.ToString() != "'" && currentChar != '@')
- {
- for (int j = 0; j < key; j++)
- {
- currentChar++;
- if (currentChar == 'z' && j+1 != key)
- {
- currentChar = 'a';
- j++;
- }
- if (currentChar == 'Z' && j+1 != key)
- {
- currentChar = 'A';
- j++;
- }
- }
- }
- result += currentChar;
- }
- Console.WriteLine($"Successful encryption: {result}");
- result = string.Empty;
- }
- else
- {
- Console.WriteLine("Invalid input!");
- }
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement