petarkobakov

The Imitation game

Aug 15th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace The_Imitation_Game
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string encryptedMessage = Console.ReadLine();
  12. StringBuilder result = new StringBuilder(encryptedMessage);
  13.  
  14. string command = Console.ReadLine();
  15.  
  16. while (command!= "Decode")
  17. {
  18. string[] instructions = command.Split('|').ToArray();
  19. string operation = instructions[0];
  20.  
  21.  
  22. switch (operation)
  23. {
  24. case "Move":
  25. int countOfLetterToMove = int.Parse(instructions[1]);
  26. string substring = result.ToString().Substring(0, countOfLetterToMove);
  27. result.Append(substring);
  28.  
  29. result.Remove(0, substring.Length);
  30.  
  31.  
  32. break;
  33.  
  34. case "Insert":
  35. int index = int.Parse(instructions[1]);
  36. string value = instructions[2];
  37.  
  38. result.Insert(index, value);
  39.  
  40.  
  41. break;
  42.  
  43. case "ChangeAll":
  44. substring = instructions[1];
  45. string replacement = instructions[2];
  46.  
  47. result.Replace(substring, replacement);
  48.  
  49. break;
  50.  
  51. }
  52. command = Console.ReadLine();
  53. }
  54.  
  55. Console.WriteLine($"The decrypted message is: {result}");
  56. }
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment