Advertisement
bobypenev

08. Use Your Chains, Buddy

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