Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace PencilCode
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<char, int> chars = new Dictionary<char, int>
  14.             {
  15.                 {'A', 0x41},
  16.                 {'B', 0x61},
  17.                 {'C', 0x31},
  18.                 {'D', 0x42},
  19.                 {'E', 0x43},
  20.                 {'F', 0x32},
  21.                 {'G', 0x51},
  22.                 {'H', 0x33},
  23.                 {'I', 0x34},
  24.                 {'J', 0x35},
  25.                 {'K', 0x36},
  26.                 {'L', 0x21},
  27.                 {'M', 0x44},
  28.                 {'N', 0x37},
  29.                 {'O', 0x45},
  30.                 {'P', 0x46},
  31.                 {'Q', 0x52},
  32.                 {'R', 0x53},
  33.                 {'S', 0x54},
  34.                 {'T', 0x22},
  35.                 {'U', 0x38},
  36.                 {'V', 0x23},
  37.                 {'W', 0x47},
  38.                 {'X', 0x24},
  39.                 {'Y', 0x25},
  40.                 {'Z', 0x39},
  41.                 {'0', 0x48},
  42.                 {'1', 0x26},
  43.                 {'2', 0x55},
  44.                 {'3', 0x56},
  45.                 {'4', 0x3A},
  46.                 {'5', 0x57},
  47.                 {'6', 0x58},
  48.                 {'7', 0x3B},
  49.                 {'8', 0x62},
  50.                 {'9', 0x59}
  51.             };
  52.  
  53.             var magic = "83cd09c9cb593d5bf871e8d71035b4a7";
  54.  
  55.             while (true)
  56.             {
  57.                 var text = Console.ReadLine().ToUpper();
  58.                 if(text.Length < 3)
  59.                 {
  60.                     Console.WriteLine("Invalid input!");
  61.                     continue;
  62.                 }
  63.                 var result = string.Concat(
  64.                     (from c in text
  65.                      select (chars.ContainsKey(c) ? chars[c] : Encoding.ASCII.GetBytes(c.ToString())[0])).Select(
  66.                          (t, i) => int.Parse(magic[i % 32].ToString(), NumberStyles.HexNumber) * t).Select(x => x.ToString("x")));
  67.  
  68.                 var even = result.Where((t, i) => i % 2 == 0).Reverse();
  69.                 var odd = result.Where((t, i) => i % 2 != 0);
  70.  
  71.  
  72.                 Console.WriteLine(string.Concat(even) + string.Concat(odd));
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement