Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TheImitationGame
- {
- class Program
- {
- static void Main(string[] args)
- {
- string encryptedMessage = Console.ReadLine();
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "Decode")
- {
- string[] commandArray = command.Split('|');
- if (commandArray[0] == "Move")
- {
- int n = int.Parse(commandArray[1]);
- string firstNLetters = encryptedMessage.Substring(0, n);
- int lastLettersLength = encryptedMessage.Length - n;
- string lastLetters = encryptedMessage.Substring(n, lastLettersLength);
- string newString = lastLetters + firstNLetters;
- encryptedMessage = newString;
- }
- else if (commandArray[0] == "Insert")
- {
- int index = int.Parse(commandArray[1]);
- string value = commandArray[2];
- encryptedMessage = encryptedMessage.Insert(index, value);
- }
- else if (commandArray[0] == "ChangeAll")
- {
- string substring = commandArray[1];
- string replacement = commandArray[2];
- while (encryptedMessage.Contains(substring))
- {
- encryptedMessage = encryptedMessage.Replace(substring, replacement);
- }
- }
- }
- Console.WriteLine($"The decrypted message is: {encryptedMessage}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement