Advertisement
ivanov_ivan

EncryptDecrypt

Oct 4th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 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 Testing
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Encrypting
  14.  
  15.             string inputCode = Console.ReadLine();
  16.  
  17.  
  18.             string encryptedText = string.Empty;
  19.  
  20.             for(int i = 0; i < inputCode.Length; i++)
  21.             {
  22.                 encryptedText += (int)inputCode[i];
  23.             }
  24.             Console.WriteLine(encryptedText);
  25.                
  26.             //Decrypting
  27.  
  28.             string decryptedText = string.Empty;
  29.  
  30.             for (int i = 0; i < encryptedText.Length;)
  31.             {
  32.                 int character = int.Parse(encryptedText.Substring(i, 2));
  33.                 char symbol = Convert.ToChar(character);
  34.                 if (char.IsLetterOrDigit(symbol) || (character >=32 && character<=47))
  35.                 {
  36.                     decryptedText += symbol;
  37.                     i += 2;
  38.                     continue;
  39.                 }
  40.                 else
  41.                 {
  42.                     int curentChar = int.Parse(encryptedText.Substring(i, 3));
  43.                     char currentSymbol = Convert.ToChar(curentChar);
  44.                     decryptedText += currentSymbol;
  45.                     i += 3;
  46.                 }
  47.                
  48.             }
  49.  
  50.             Console.WriteLine(decryptedText);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement