Advertisement
bobypenev

08. Use Your Chains, Buddy

Jun 19th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8.  
  9. namespace UseYourChainsBuddy
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));
  16.  
  17.             // Decrypted manual
  18.             List<string> manual = new List<string>();
  19.             string input = Console.ReadLine();
  20.  
  21.             // Find text inside <p> tags
  22.             string tagPattern = @"<p>(.+?)<\/p>";
  23.             MatchCollection inputMatches = Regex.Matches(input, tagPattern);
  24.             foreach (Match match in inputMatches)
  25.             {
  26.                 string rawText = match.Groups[1].Value;
  27.                 // Leave only small letters and digits - the rest replace with a space
  28.                 string alphanumPattern = @"[^a-z0-9]+";
  29.                 rawText = Regex.Replace(rawText, alphanumPattern, " ");
  30.  
  31.                 // Do a ROT13
  32.                 StringBuilder rot13Text = new StringBuilder(rawText);
  33.                 for (int i = 0; i < rot13Text.Length; i++)
  34.                 {
  35.                     char letter = rot13Text[i];
  36.                     if (letter >= 'a' && letter <= 'm')
  37.                     {
  38.                         rot13Text[i] = (char)(letter + 13);
  39.                     }
  40.                     else if ( letter > 'm' && letter <= 'z' )
  41.                     {
  42.                         rot13Text[i] = (char)(letter - 13);
  43.                     }
  44.                 }
  45.  
  46.                 // Add decrypted text to manual
  47.                 manual.Add(rot13Text.ToString().Trim());
  48.             }
  49.  
  50.             Console.WriteLine(string.Join(" ", manual));
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement