Advertisement
SonOfABeach

Untitled

Feb 5th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. private string Encrypt(string Input, int TranslationValue = 5)
  2.         {
  3.             string Encrypted = "";
  4.             Input = Input.ToLower();
  5.             for (int i = 0; i <= Input.Length - 1; i++)
  6.             {
  7.                 int CharNum = FindCharLocation(Input[i]);
  8.                 if (CharNum != -1)
  9.                 {
  10.                     if (CharNum >= Alphabet.Length - TranslationValue)
  11.                     {
  12.                         Encrypted += Alphabet[TranslationValue - (Alphabet.Length - CharNum)];
  13.                     }
  14.                     else
  15.                     {
  16.                         Encrypted += Alphabet[CharNum + TranslationValue];
  17.                     }
  18.                 }
  19.                 else
  20.                 {
  21.                     Encrypted += Input[i];
  22.                 }
  23.             }
  24.             return Encrypted;
  25.         }
  26.  
  27.         private string Decrypt(string Input, int TranslationValue = 5)
  28.         {
  29.             string Decrypted = "";
  30.             Input = Input.ToLower();
  31.             for (int i = 0; i <= Input.Length - 1; i++)
  32.             {
  33.                 int CharNum = FindCharLocation(Input[i]);
  34.                 if (CharNum != -1)
  35.                 {
  36.                     if (CharNum < TranslationValue)
  37.                     {
  38.                         Decrypted += Alphabet[Alphabet.Length - (TranslationValue - CharNum)];
  39.                     }
  40.                     else
  41.                     {
  42.                         Decrypted += Alphabet[CharNum - TranslationValue];
  43.                     }
  44.                 }
  45.                 else
  46.                 {
  47.                     Decrypted += Input[i];
  48.                 }
  49.             }
  50.             return Decrypted;
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement