petarkobakov

Message Encrypter

Aug 5th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Message_Encrypter
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int messages = int.Parse(Console.ReadLine());
  11. Regex pattern = new Regex(@"(\*|@)(?<tag>[A-Z][a-z]{2,})(\1).\s(?<code>[[][A-Za-z][]][|][[][A-Za-z][]][|][[][A-Za-z][]][|]$)");
  12.  
  13. for (int i = 0; i < messages; i++)
  14. {
  15. string input = Console.ReadLine();
  16. Match valid = pattern.Match(input);
  17.  
  18. if (valid.Success)
  19. {
  20. Console.Write($"{ valid.Groups["tag"].Value}: ");
  21.  
  22. string codeToEnrypt = valid.Groups["code"].Value;
  23. codeToEnrypt = codeToEnrypt.Replace("[","").Replace("]", "").Replace("|", "");
  24.  
  25.  
  26. foreach (var ch in codeToEnrypt)
  27. {
  28. Console.Write($"{(int)(ch)} ");
  29. }
  30.  
  31. Console.WriteLine();
  32. }
  33. else
  34. {
  35. Console.WriteLine("Valid message not found!");
  36. }
  37. }
  38.  
  39. }
  40. }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment