Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace _02.Spy_Gram
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. var priviteKey = Console.ReadLine();
  15. var text = Console.ReadLine();
  16. var structure = @"^TO: ([A-Z]+); MESSAGE: (.+);$";
  17. var textToPrint = "";
  18. var result = new Dictionary<string, string>();
  19.  
  20. while (text!="END")
  21. {
  22. Regex r = new Regex(structure, RegexOptions.None);
  23. Match m = r.Match(text);
  24. if (r.IsMatch(text))
  25. {
  26. var addingText = TurningMessage(priviteKey, text, textToPrint);
  27. var names = m.Groups[1].Value;
  28. result[names] = addingText;
  29.  
  30. //Console.WriteLine(names);
  31. };
  32.  
  33. textToPrint = "";
  34.  
  35.  
  36.  
  37. text = Console.ReadLine();
  38. }
  39. foreach (var message in result.OrderBy(a=>a.Key))
  40. {
  41. Console.WriteLine(message.Value);
  42. }
  43. }
  44.  
  45. private static string TurningMessage(string priviteKey, string text, string textToPrint)
  46. {
  47. var j = 0;
  48. for (int i = 0; i < text.Length; i++)
  49. {
  50. if (j==priviteKey.Length)
  51. {
  52. j = 0;
  53. }
  54. var symvol = priviteKey[j] - '0';
  55. var newSymvol = (char)((char)text[i] + symvol);
  56. textToPrint += newSymvol;
  57. j++;
  58. }
  59. return textToPrint;
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement