private void MyShifr2(int m, string text) { char[] engAlp = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X','Y','Z', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; char[] alphabet = { 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к','л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц','ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я' }; string[] shifredAlp = new string[33]; foreach (char shifrChar in alphabet) { int index = Array.IndexOf(alphabet, shifrChar) - 7; int index1 = Array.IndexOf(alphabet, shifrChar); int a = CAR(index - 7); int b = CAR(index + 13); int c = CAR(index - 18); int d = CAR(index + 10); int e = CAR(index - 8); int f = CAR(index + 4); string toShifr = engAlp[a].ToString() + engAlp[b].ToString() + engAlp[c].ToString() + engAlp[d].ToString() + engAlp[e].ToString() + engAlp[f].ToString(); shifredAlp[index1] = toShifr; } switch (m) { case (0): { string toShifrText = text; foreach (char Charkey in alphabet) { int index = Array.IndexOf(alphabet, Charkey); string shifrReplace = shifredAlp[index] + "_"; string ckey = Charkey.ToString(); Regex reg = new Regex(ckey, RegexOptions.IgnoreCase); toShifrText = reg.Replace(toShifrText, shifrReplace); } if (toShifrText.EndsWith("_")) { toShifrText = toShifrText.Remove(toShifrText.Length - 1); } text2.Text = toShifrText; break; } case (1): { string toShifrText = text; foreach (string Charkey in shifredAlp) { int index = Array.IndexOf(shifredAlp, Charkey); string alphabetReplace = alphabet[index].ToString(); string ckey = Charkey.ToString(); Regex reg = new Regex(ckey); toShifrText = reg.Replace(toShifrText, alphabetReplace); } toShifrText = ConvertStringArrayToString(toShifrText.Split('_')); text2.Text = toShifrText; break; } } }
private void MyShifr1(int key, int m, string text) { char[] alphabet = { 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к','л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц','ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я' }; string[] shifr = new string[33]; foreach (char ch in alphabet) { int index = Array.IndexOf(alphabet, ch) + 1; string one = (index * (key + 3)).ToString(); string two = (index * (key + 1)).ToString(); string three = (index * (key + 5)).ToString(); string four = (index * (key + 2)).ToString(); string complete = (Int64.Parse(one) * Int64.Parse(two) * Int64.Parse(three)).ToString() + four; shifr[index - 1] = (complete); //Int64.Parse(complete); } switch (m) { case (0): { string toShifr = text; foreach (char Charkey in alphabet) { int index = Array.IndexOf(alphabet, Charkey); string shifrReplace = shifr[index].ToString(); string ckey = Charkey.ToString(); Regex reg = new Regex(ckey, RegexOptions.IgnoreCase); toShifr = reg.Replace(toShifr, shifrReplace); } text2.Text = toShifr; break; } case (1): { string toShifr = text; foreach (string Charkey in shifr) { int index = Array.IndexOf(shifr, Charkey); string alphabetReplace = alphabet[index].ToString(); string ckey = Charkey.ToString(); Regex reg = new Regex(ckey); toShifr = reg.Replace(toShifr, alphabetReplace); } text2.Text = toShifr; break; } } }