Не получается дешифровать текст методом гаммирования - C#
Формулировка задачи:
Хочу методом гаммирования дешифровать текст и у меня получается так что текст шифруется вроде правильно а дешифрует кракозявры и ошибка в этой строке textBox6.Text += text[z];
скажите пожалуйста что я не правильно делаю
button1 - Шифрует текст
button2 - Должен дешифровать текст
пытался делать по этому уроку http://edu.dvgups.ru/METDOC/ENF/PRMA..._MET/Kom_4.htm
Если нужен проект то вот держите
arch1.rar
private void button1_Click(object sender, EventArgs e)
{
string entertext1 = textBox1.Text;
string entertext2 = textBox2.Text;
string key="";
textBox3.Clear();
while (key.Length < entertext1.Length)
{
key += entertext2;
if (key.Length > entertext1.Length) key = key.Remove(key.Length - 2);
}
for (int i = 0; i < entertext1.Length; i++)
{
for (int id = 0; id < 44; id++)
{
if (key[i] == text[id]) k = id;
if (entertext1[i] == text[id]) x = id;
z = (x+k) % 44;
}
textBox3.Text += text[z];
}
}
private void button2_Click(object sender, EventArgs e)
{
string entertext4 = textBox1.Text;
string entertext5 = textBox2.Text;
string key = "";
textBox6.Clear();
while (key.Length < entertext4.Length)
{
key += entertext5;
if (key.Length > entertext4.Length) key = key.Remove(key.Length - 2);
}
for (int i = 0; i < entertext4.Length; i++)
{
for (int id = 0; id < 44; id++)
{
if (key[i] == text[id]) k = id;
if (entertext4[i] == text[id]) x = id;
z = ((entertext4[i]-key[i])+44) % 44;
}
textBox6.Text += text[z];
}
}Решение задачи: «Не получается дешифровать текст методом гаммирования»
textual
Листинг программы
string entertext4 = textBox4.Text; string entertext5 = textBox5.Text;