ralichka

FinalExamPrep-24.07.2019-02.Song

Dec 6th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _02.SongEcryption
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.  
  12.             while (input != "end")
  13.             {
  14.                 Regex regex = new Regex(@"^([A-z][a-z' ]+):([A-Z ]+)$");
  15.                 Match matches = regex.Match(input);
  16.  
  17.                 if (matches.Success)
  18.                 {
  19.                     string artist = matches.Groups[1].Value;
  20.                     string song = matches.Groups[2].Value;
  21.                     string newArtist = "";
  22.                     int key = artist.Length;
  23.                     int valueArtist;
  24.                     int valueSong;
  25.                     string newSong = "";
  26.  
  27.                     for (int i = 0; i < key; i++)
  28.                     {
  29.                         char current = artist[i];
  30.                         if (current != ' ' && current != '\'')
  31.                         {
  32.  
  33.                             valueArtist = current + key;
  34.                             if (char.IsLower(current) && valueArtist > 'z')
  35.                             {
  36.  
  37.                                 valueArtist = valueArtist - 'z' + ('a' - 1);
  38.                             }
  39.                             if (char.IsUpper(current) && valueArtist > 'Z')
  40.                             {
  41.                                 valueArtist = valueArtist - 'Z' + ('A' - 1);
  42.                             }
  43.                             newArtist += (char)valueArtist;
  44.                         }
  45.                         else
  46.                         {
  47.                             newArtist += current;
  48.                         }
  49.                     }
  50.                     for (int i = 0; i < song.Length; i++)
  51.                     {
  52.                         char currentLetter = song[i];
  53.                         if (currentLetter != ' ' && currentLetter != '\'')
  54.                         {
  55.                             valueSong = currentLetter + key;
  56.                             if (char.IsLower(currentLetter) && valueSong > 'z')
  57.                             {
  58.                                 valueSong = valueSong - 'z' + ('a' - 1);
  59.                             }
  60.                             if (char.IsUpper(currentLetter) && valueSong > 'Z')
  61.                             {
  62.                                 valueSong = valueSong - 'Z' + ('A' - 1);
  63.                             }
  64.                             newSong += (char)valueSong;
  65.  
  66.                         }
  67.                         else
  68.                         {
  69.                             newSong += currentLetter;
  70.                         }
  71.                     }
  72.                     //string password = newArtist + "@" + song;
  73.  
  74.                     Console.WriteLine($"Successful encryption: {newArtist}@{newSong}");
  75.                 }
  76.                 else
  77.                 {
  78.                     Console.WriteLine("Invalid input!");
  79.                 }
  80.                 input = Console.ReadLine();
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment