krasi1105

Text Transformer

Jul 20th, 2017
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Program
  7. {
  8.     public static void Main()
  9.     {
  10.         var input = ReadInput();
  11.         var specialSymbols = new[] { '$', '%', '&', '\'' };
  12.         Regex rgx = new Regex(@"([$%&'])([^$%&']+)\1");
  13.         StringBuilder output = new StringBuilder();
  14.         Match m = rgx.Match(input);
  15.         while (m.Success)
  16.         {
  17.             var message = m.Value;
  18.             if (message.Length > 2)
  19.             {
  20.                 var messageBody = message.Substring(1, message.Length - 2);
  21.                 var charWeight = Array.IndexOf(specialSymbols, message[0]) + 1;
  22.                 var decrypted = DecryptMessage(messageBody, charWeight);
  23.                 output.Append($"{decrypted} ");
  24.             }
  25.             m = rgx.Match(input, m.Index + m.Length);
  26.         }
  27.  
  28.  
  29.         Console.WriteLine(output.ToString());
  30.     }
  31.  
  32.     private static string ReadInput()
  33.     {
  34.         var sb = new StringBuilder();
  35.         string input;
  36.         while (!(input = Console.ReadLine()).Equals("burp"))
  37.         {
  38.             sb.Append(input);
  39.         }
  40.  
  41.         string allLines = sb.ToString();
  42.         allLines = Regex.Replace(allLines, @"\s{2,}", " ");
  43.         return allLines;
  44.     }
  45.     private static string DecryptMessage(string messageBody, int charWeight)
  46.     {
  47.         StringBuilder result = new StringBuilder(messageBody.Length);
  48.         foreach (var letter in messageBody)
  49.         {
  50.             result.Append((char)(letter + charWeight));
  51.             charWeight = -charWeight;
  52.         }
  53.         return result.ToString();
  54.     }
  55. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×