Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace cryptCaesar
- {
- class Crypt
- {
- string alph = "ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮйцукенгшщзхъфывапролджэячсмитьбюQWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890,.";
- public string encrypt(int key, string text) {
- int lenalph = alph.Length;
- int tmp;
- string res = "";
- foreach (char c in text)
- {
- if (alph.IndexOf(c)!=-1)
- {
- tmp = (alph.IndexOf(c) + key) % lenalph;
- res += alph[tmp];
- }
- else
- res += c;
- }
- return res;
- }
- public string decrypt(int key, string text)
- {
- int lenalph = alph.Length;
- int tmp;
- string res = "";
- foreach (char c in text)
- {
- if (alph.IndexOf(c) != -1)
- {
- tmp = (alph.IndexOf(c) - key + lenalph) % lenalph;
- res += alph[tmp];
- }
- else
- res += c;
- }
- return res;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement