Advertisement
Guest User

Untitled

a guest
May 6th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 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 cryptCaesar
  8. {
  9.     class Crypt
  10.     {
  11.         string alph = "ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮйцукенгшщзхъфывапролджэячсмитьбюQWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890,.";
  12.         public string encrypt(int key, string text) {
  13.  
  14.             int lenalph = alph.Length;
  15.             int tmp;
  16.             string res = "";
  17.  
  18.             foreach (char c in text)
  19.             {
  20.                 if (alph.IndexOf(c)!=-1)
  21.                 {
  22.                     tmp = (alph.IndexOf(c) + key) % lenalph;
  23.                     res += alph[tmp];
  24.                 }
  25.                 else
  26.                     res += c;
  27.             }
  28.             return res;
  29.         }
  30.  
  31.         public string decrypt(int key, string text)
  32.         {
  33.  
  34.             int lenalph = alph.Length;
  35.             int tmp;
  36.             string res = "";
  37.  
  38.             foreach (char c in text)
  39.             {
  40.                 if (alph.IndexOf(c) != -1)
  41.                 {
  42.                     tmp = (alph.IndexOf(c) - key + lenalph) % lenalph;
  43.                     res += alph[tmp];
  44.                 }
  45.                 else
  46.                     res += c;
  47.             }
  48.             return res;
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement