Advertisement
grubcho

String encryption

Jun 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace encription
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             string cypher = string.Empty;
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 char letter = char.Parse(Console.ReadLine());
  18.                 cypher+=Encrypt(letter);                                
  19.             }
  20.             Console.WriteLine(cypher);
  21.         }
  22.         static string Encrypt(char letter)
  23.         {
  24.             int asciiCode = letter;
  25.             int appendFirstLast = asciiCode;
  26.             string append = string.Empty;
  27.             string midlle = string.Empty;
  28.             if (asciiCode >= 100)
  29.             {
  30.                 while (appendFirstLast > 0)
  31.                 {
  32.                     append = (appendFirstLast % 10).ToString();
  33.                     midlle = midlle.Insert(0, append);
  34.                     appendFirstLast /= 100;
  35.                 }
  36.             }
  37.             else if (asciiCode < 100)
  38.             {
  39.                 while (appendFirstLast > 0)
  40.                 {
  41.                     append = (appendFirstLast % 10).ToString();
  42.                     midlle = midlle.Insert(0, append);
  43.                     appendFirstLast /= 10;
  44.                 }
  45.             }            
  46.             int intMidlle = int.Parse(midlle);
  47.             char start = (char)(asciiCode + (intMidlle % 10));
  48.             char end = (char)(asciiCode - ((intMidlle / 10) % 10));
  49.             string cypher = start + midlle + end;
  50.             return cypher;
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement