Advertisement
Guest User

MasloCoder

a guest
Mar 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace Coder
  10. {
  11.     class Program
  12.     {
  13.         private static Dictionary<string, string> LetterDic = new Dictionary<string, string>();
  14.         static void Main(string[] args)
  15.         {
  16.             bool Decode = false;
  17.             LetterDic.Add("33.442.552.22.441.551", "A");
  18.             while (true)
  19.             {
  20.                 Console.WriteLine("Code [C] Or Decode? [D]");
  21.                 Console.Write("Input: ");
  22.                 var Input = Console.ReadLine();
  23.                 if (Input == "D") Decode = true;
  24.                 else Decode = false;
  25.                 if (Decode)
  26.                 {
  27.                     Console.WriteLine("Enter string to decode separate with ','");
  28.                     var toDecode = Console.ReadLine();
  29.                     DecoderText(toDecode);
  30.                 }
  31.                 else
  32.                 {
  33.                     Console.WriteLine("Enter string to code");
  34.                     var toCode = Console.ReadLine();
  35.                     CoderText(toCode);
  36.                 }
  37.  
  38.             }
  39.         }
  40.  
  41.         static void DecoderText(string ToDecode)
  42.         {
  43.             List<string> stringList = ToDecode.Split(',').ToList();
  44.             string LetterToWrite;
  45.             Console.Clear();
  46.             Console.Write ("DecoderResult: ");
  47.             foreach (var test in stringList)
  48.             {
  49.                 LetterDic.TryGetValue(test, out LetterToWrite);
  50.                 Console.Write(LetterToWrite);
  51.             }
  52.             Console.WriteLine();
  53.             Console.WriteLine("Enter any key to goto to menu!");
  54.             Console.ReadKey();
  55.         }
  56.  
  57.         static void CoderText(string ToCode)
  58.         {
  59.             List<char> charList = new List<char>(ToCode.Length);
  60.             foreach (var c in ToCode)
  61.             {
  62.                 charList.Add(c);
  63.             }
  64.             Console.Clear();
  65.             Console.Write("CoderResult: ");
  66.             foreach (var test in charList)
  67.             {
  68.                 var coder = LetterDic.FirstOrDefault(x => x.Value.Contains(test)).Key;
  69.                 Console.Write(coder);
  70.                 Console.Write(",");
  71.                 coder = "";
  72.             }
  73.             Console.WriteLine();
  74.             Console.WriteLine("Enter any key to goto to menu!");
  75.             Console.ReadKey();
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement