Advertisement
parunowaa

01.Imitation_Game

Dec 10th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace _01.Imitation_Game
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string encryptedMessage = Console.ReadLine();
  12.             string instructions = Console.ReadLine();
  13.             string message = encryptedMessage;
  14.  
  15.             while (instructions != "Decode")
  16.             {
  17.                 string[] cmd = instructions.Split('|').ToArray();
  18.                 var cmd1 = cmd[0];
  19.                 var cmd2 = cmd[1];
  20.  
  21.  
  22.                 if (cmd1 == "Move")
  23.                 {
  24.                     string substr = message.Substring(0, int.Parse(cmd2));
  25.                     string editedMessage = message.Insert(message.Length, substr).Remove(0, int.Parse(cmd2));
  26.                     message = editedMessage;
  27.                 }
  28.                 if (cmd1 == "Insert")
  29.                 {
  30.                     var cmd3 = cmd[2];
  31.                     string editedMessage = message.Insert(int.Parse(cmd2), cmd3);
  32.                     message = editedMessage;
  33.                 }
  34.                 if (cmd1 == "ChangeAll")
  35.                 {
  36.                     var cmd3 = cmd[2];
  37.                     string editedMessage = message.Replace(cmd2, cmd3);
  38.                     message = editedMessage;
  39.                 }
  40.                 instructions = Console.ReadLine();
  41.             }
  42.  
  43.             Console.WriteLine($"The decrypted message is: {message}");
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement