Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace song_encryption
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool invalid = false;
- String[] input;
- List<String> artist = new List<String>();
- List<String> song = new List<String>();
- do
- {
- input = Console.ReadLine().Split(':').ToArray();
- if (input[0] != "end")
- {
- artist.Add(input[0]);
- song.Add(input[1]);
- }
- } while (input[0] != "end");
- for (int j = 0; j < artist.Count; j++)
- {
- if (!(artist.ElementAt(j)[0] >= 'A' && artist.ElementAt(j)[0] <= 'Z'))
- {
- Console.WriteLine("Invalid input!");
- }
- else
- {
- for (int i = 1; i < artist.ElementAt(j).Length; i++)
- {
- if (!(artist.ElementAt(j)[i] >= 'a' && artist.ElementAt(j)[i] <= 'z' || artist.ElementAt(j)[i] == ' ' || artist.ElementAt(j)[i] == '\''))
- {
- invalid = true;
- }
- }
- for (int i = 0; i < song.ElementAt(j).Length; i++)
- {
- if (!(song.ElementAt(j)[i] >= 'A' && song.ElementAt(j)[i] <= 'Z' || song.ElementAt(j)[i] == ' '))
- {
- invalid = true;
- }
- }
- if (invalid == false)
- {
- int encryptionKey = artist.ElementAt(j).Length;
- List<char> encryptedArtist = artist.ElementAt(j).ToList();
- List<char> encryptedSong = song.ElementAt(j).ToList();
- if ((encryptedArtist[0] + encryptionKey) <= 'Z')
- {
- encryptedArtist[0] = (char)(encryptedArtist[0] + encryptionKey);
- }
- else
- {
- int temp = (encryptedArtist[0] + encryptionKey) - 'Z';
- encryptedArtist[0] = (char)('A' + temp);
- }
- for (int i = 1; i < encryptedArtist.Count; i++)
- {
- if (encryptedArtist.ElementAt(i) != ' ' && encryptedArtist.ElementAt(i) != '\'' && (encryptedArtist.ElementAt(i) + encryptionKey) <= 'z')
- {
- char element = encryptedArtist.ElementAt(i);
- encryptedArtist.RemoveAt(i);
- encryptedArtist.Insert(i,(char)(element + encryptionKey));
- }
- if (encryptedArtist.ElementAt(i) != ' ' && encryptedArtist[i] != '\'' && (encryptedArtist[i] + encryptionKey) > 'z')
- {
- char element = encryptedArtist.ElementAt(i);
- int temp = (element + encryptionKey) - 'z';
- encryptedArtist.RemoveAt(i);
- encryptedArtist.Insert(i, (char)('a' + temp));
- }
- }
- for (int i = 0; i < encryptedSong.Count; i++)
- {
- if (encryptedSong.ElementAt(i) != ' ' && (encryptedSong.ElementAt(i) + encryptionKey) <= 'Z')
- {
- char element = encryptedSong.ElementAt(i);
- encryptedSong.RemoveAt(i);
- encryptedSong.Insert(i, (char)(element + encryptionKey));
- //encryptedSong[i] = (char)(encryptedSong[i] + encryptionKey);
- }
- else
- {
- char element = encryptedSong.ElementAt(i);
- int temp = (element + encryptionKey) - 'Z';
- encryptedSong.RemoveAt(i);
- encryptedSong.Insert(i, (char)('A' + temp));
- /*int temp = (encryptedSong[i] + encryptionKey) - 'Z';
- encryptedSong[i] = (char)('A' + temp);*/
- }
- }
- Console.Write("Successful encryption: ");
- for(int i = 0; i < encryptedArtist.Count; i++)
- {
- Console.Write(encryptedArtist.ElementAt(i));
- }
- Console.Write("@");
- for (int i = 0; i < encryptedSong.Count; i++)
- {
- Console.Write(encryptedSong.ElementAt(i));
- }
- Console.WriteLine();
- }
- else
- {
- invalid = false;
- Console.WriteLine("Invalid input!");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement