Deserboy

Message Encrypter

Aug 6th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 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.Text.RegularExpressions;
  6.  
  7. namespace ConsoleApp4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 string message = Console.ReadLine();
  17.                 Regex regex = new Regex(@"(\*|@)([A-Z][a-z]{2,})\1: \[(\w)\]\|\[(\w)\]\|\[(\w)\]\|$");
  18.                 bool match = regex.IsMatch(message);
  19.                 Match tag = regex.Match(message);
  20.                 string tagString = tag.Groups[2].Value;
  21.                 if (match == false)
  22.                 {
  23.                     Console.WriteLine("Valid message not found!");
  24.                 }
  25.                 else
  26.                 {
  27.                     Regex groups = new Regex(@"(\*|@)([A-Z][a-z]{2,})\1: \[(\w)\]\|\[(\w)\]\|\[(\w)\]\|$");
  28.                     Match matching = groups.Match(message);
  29.                     string firstGroup = matching.Groups[3].Value;
  30.                     string secondGroup = matching.Groups[4].Value;
  31.                     string thirdGroup = matching.Groups[5].Value;
  32.                     char firstChar = char.Parse(firstGroup);
  33.                     char secondChar = char.Parse(secondGroup);
  34.                     char thirdChar = char.Parse(thirdGroup);
  35.                     int firstValue = (int)firstChar;
  36.                     int secondValue = (int)secondChar;
  37.                     int thirdValue = (int)thirdChar;
  38.                     string stringValue = firstValue.ToString() + " " + secondValue.ToString() + " " + thirdValue.ToString();
  39.                     Console.WriteLine($"{tagString}: {stringValue}");
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment