Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace SongEncryption
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             //string pattern = @"(^[A-Z]{1}[a-z]+[\s|'a-z]*):([A-Z\s*]+\b)";
  11.             string pattern = @"^([A-Z]{1}[a-z\' ]+):([A-Z ]+)\b";
  12.             string input = Console.ReadLine();
  13.             string result = string.Empty;
  14.  
  15.  
  16.             while (input != "end")
  17.             {
  18.                 Match singerAndSong = Regex.Match(input, pattern);
  19.  
  20.                 if (singerAndSong.Success)
  21.                 {
  22.                     int key = singerAndSong.Groups["1"].Value.Length;
  23.                     string song = singerAndSong.Groups["2"].Value;
  24.                     input = input.Replace(":", "@");
  25.                     for (int i = 0; i < input.Length; i++)
  26.                     {
  27.                         char currentChar = input[i];
  28.                         if (currentChar != ' ' && currentChar.ToString() != "'" && currentChar != '@')
  29.                         {
  30.                             for (int j = 0; j < key; j++)
  31.                             {
  32.  
  33.                                 currentChar++;
  34.                                 if (currentChar == 'z' && j+1 != key)
  35.                                 {
  36.                                     currentChar = 'a';
  37.                                     j++;
  38.                                 }
  39.                                 if (currentChar == 'Z' && j+1 != key)
  40.                                 {
  41.                                     currentChar = 'A';
  42.                                     j++;
  43.                                 }
  44.                             }
  45.                         }
  46.                         result += currentChar;
  47.                    
  48.                     }
  49.                     Console.WriteLine($"Successful encryption: {result}");
  50.                     result = string.Empty;
  51.                 }
  52.                 else
  53.                 {
  54.                     Console.WriteLine("Invalid input!");
  55.                 }
  56.  
  57.  
  58.  
  59.                 input = Console.ReadLine();
  60.             }
  61.  
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement