Advertisement
Guest User

SRYDANKA

a guest
Dec 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace song_encryption
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool invalid = false;
  14.             String[] input;
  15.             List<String> artist = new List<String>();
  16.             List<String> song = new List<String>();
  17.             do
  18.             {
  19.                 input = Console.ReadLine().Split(':').ToArray();
  20.                 if (input[0] != "end")
  21.                 {
  22.                     artist.Add(input[0]);
  23.                     song.Add(input[1]);
  24.                 }
  25.             } while (input[0] != "end");
  26.  
  27.             for (int j = 0; j < artist.Count; j++)
  28.             {
  29.                 if (!(artist.ElementAt(j)[0] >= 'A' && artist.ElementAt(j)[0] <= 'Z'))
  30.                 {
  31.                     Console.WriteLine("Invalid input!");
  32.                 }
  33.                 else
  34.                 {
  35.                     for (int i = 1; i < artist.ElementAt(j).Length; i++)
  36.                     {
  37.                         if (!(artist.ElementAt(j)[i] >= 'a' && artist.ElementAt(j)[i] <= 'z' || artist.ElementAt(j)[i] == ' ' || artist.ElementAt(j)[i] == '\''))
  38.                         {
  39.                             invalid = true;
  40.                         }
  41.                     }
  42.                     for (int i = 0; i < song.ElementAt(j).Length; i++)
  43.                     {
  44.                         if (!(song.ElementAt(j)[i] >= 'A' && song.ElementAt(j)[i] <= 'Z' || song.ElementAt(j)[i] == ' '))
  45.                         {
  46.                             invalid = true;
  47.                         }
  48.                     }
  49.                     if (invalid == false)
  50.                     {
  51.                         int encryptionKey = artist.ElementAt(j).Length;
  52.                         List<char> encryptedArtist = artist.ElementAt(j).ToList();
  53.                         List<char> encryptedSong = song.ElementAt(j).ToList();
  54.                        
  55.                         if ((encryptedArtist[0] + encryptionKey) <= 'Z')
  56.                         {
  57.                             encryptedArtist[0] = (char)(encryptedArtist[0] + encryptionKey);
  58.                         }
  59.                         else
  60.                         {
  61.                             int temp = (encryptedArtist[0] + encryptionKey) - 'Z';
  62.                             encryptedArtist[0] = (char)('A' + temp);
  63.                         }
  64.                         for (int i = 1; i < encryptedArtist.Count; i++)
  65.                         {
  66.                             if (encryptedArtist.ElementAt(i) != ' ' && encryptedArtist.ElementAt(i) != '\'' && (encryptedArtist.ElementAt(i) + encryptionKey) <= 'z')
  67.                             {
  68.                                 char element = encryptedArtist.ElementAt(i);
  69.                                 encryptedArtist.RemoveAt(i);
  70.                                 encryptedArtist.Insert(i,(char)(element + encryptionKey));
  71.                             }
  72.                             if (encryptedArtist.ElementAt(i) != ' ' && encryptedArtist[i] != '\'' && (encryptedArtist[i] + encryptionKey) > 'z')
  73.                             {
  74.                                 char element = encryptedArtist.ElementAt(i);
  75.                                 int temp = (element + encryptionKey) - 'z';
  76.                                 encryptedArtist.RemoveAt(i);
  77.                                 encryptedArtist.Insert(i, (char)('a' + temp));
  78.                             }
  79.                         }
  80.                         for (int i = 0; i < encryptedSong.Count; i++)
  81.                         {
  82.                             if (encryptedSong.ElementAt(i) != ' ' && (encryptedSong.ElementAt(i) + encryptionKey) <= 'Z')
  83.                             {
  84.                                 char element = encryptedSong.ElementAt(i);
  85.                                 encryptedSong.RemoveAt(i);
  86.                                 encryptedSong.Insert(i, (char)(element + encryptionKey));
  87.                                 //encryptedSong[i] = (char)(encryptedSong[i] + encryptionKey);
  88.                             }
  89.                             else
  90.                             {
  91.                                 char element = encryptedSong.ElementAt(i);
  92.                                 int temp = (element + encryptionKey) - 'Z';
  93.                                 encryptedSong.RemoveAt(i);
  94.                                 encryptedSong.Insert(i, (char)('A' + temp));
  95.  
  96.                                 /*int temp = (encryptedSong[i] + encryptionKey) - 'Z';
  97.                                 encryptedSong[i] = (char)('A' + temp);*/
  98.                             }
  99.  
  100.                         }
  101.                         Console.Write("Successful encryption: ");
  102.                         for(int i = 0; i < encryptedArtist.Count; i++)
  103.                         {
  104.                             Console.Write(encryptedArtist.ElementAt(i));
  105.                         }
  106.                         Console.Write("@");
  107.                         for (int i = 0; i < encryptedSong.Count; i++)
  108.                         {
  109.                             Console.Write(encryptedSong.ElementAt(i));
  110.                         }
  111.                         Console.WriteLine();
  112.                        
  113.                     }
  114.                     else
  115.                     {
  116.                         invalid = false;
  117.                         Console.WriteLine("Invalid input!");
  118.                     }
  119.                 }
  120.             }
  121.  
  122.         }
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement