Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace SpyGram
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string privateKey = Console.ReadLine();
  14. int counter = 0;
  15. Dictionary<string, StringBuilder> answer = new Dictionary<string, StringBuilder>();
  16. while (true)
  17. {
  18. string input = Console.ReadLine();
  19. if (input == "END")
  20. {
  21. break;
  22. }
  23. //recipient - Group1 message- Group2
  24. string pattern = @"^(?:TO)\:\s([A-Z]+)\;\s(?:MESSAGE)\:\s(.*)\;$";
  25. Regex regex = new Regex(pattern);
  26. Match match = regex.Match(input);
  27.  
  28. List<char> changedChars = new List<char>();
  29. if (!match.Success)
  30. {
  31. continue;
  32. }
  33. if (!answer.ContainsKey(match.Groups[1].ToString()))
  34. {
  35. answer.Add(match.Groups[1].ToString(), new StringBuilder());
  36. }
  37.  
  38. counter = 0;
  39. string toStringMatch = match.ToString();
  40. for (int i = 0; i < toStringMatch.Length; i++)
  41. {
  42. try
  43. {
  44. changedChars.Add(Convert.ToChar(toStringMatch[i] + int.Parse(privateKey[counter].ToString())));
  45. counter++;
  46. }
  47. catch (Exception)
  48. {
  49. counter = 0;
  50. i--;
  51. }
  52. }
  53. StringBuilder AppendingNewStr = new StringBuilder();
  54. foreach (var item in changedChars)
  55. {
  56. AppendingNewStr.Append(item);
  57. }
  58. answer[match.Groups[1].ToString()]=AppendingNewStr;
  59. }
  60. foreach (var item in answer.OrderBy(x=>x.Key))
  61. {
  62. Console.WriteLine(item.Value);
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement