Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace _02.Spy_Gram
- {
- class Program
- {
- static void Main(string[] args)
- {
- var priviteKey = Console.ReadLine();
- var text = Console.ReadLine();
- var structure = @"^TO: ([A-Z]+); MESSAGE: (.+);$";
- var textToPrint = "";
- var result = new Dictionary<string, string>();
- while (text!="END")
- {
- Regex r = new Regex(structure, RegexOptions.None);
- Match m = r.Match(text);
- if (r.IsMatch(text))
- {
- var addingText = TurningMessage(priviteKey, text, textToPrint);
- var names = m.Groups[1].Value;
- result[names] = addingText;
- //Console.WriteLine(names);
- };
- textToPrint = "";
- text = Console.ReadLine();
- }
- foreach (var message in result.OrderBy(a=>a.Key))
- {
- Console.WriteLine(message.Value);
- }
- }
- private static string TurningMessage(string priviteKey, string text, string textToPrint)
- {
- var j = 0;
- for (int i = 0; i < text.Length; i++)
- {
- if (j==priviteKey.Length)
- {
- j = 0;
- }
- var symvol = priviteKey[j] - '0';
- var newSymvol = (char)((char)text[i] + symvol);
- textToPrint += newSymvol;
- j++;
- }
- return textToPrint;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement