private void DecButton_Click(object sender, EventArgs e) { if (OutputRichTextBox.Text == "") { MessageBox.Show("Окно для расшифровки пусто"); } else if (KeyTB.TextLength < 5 || KeyTB.TextLength > 256) { MessageBox.Show("Размер ключа должен находиться в пределах от 5 до 256 символов"); } else { TimeStart(); short[] result = new short[OutputRichTextBox.TextLength]; for (int i = 0; i < OutputRichTextBox.TextLength; i++) { result[i] = (short)OutputRichTextBox.Text[i]; } short[] key = new short[KeyTB.TextLength]; for (int i = 0; i < KeyTB.TextLength; i++) { key[i] = (short)KeyTB.Text[i]; } Algorithm_RC4.AlgorithmRC4 decoder = new Algorithm_RC4.AlgorithmRC4(key); short[] decryptedBytes = decoder.Decode(result, result.Length); OutputRichTextBox.Clear(); for (int i = 0; i < decryptedBytes.Length; i++) { OutputRichTextBox.Text += (char)decryptedBytes[i]; } TimeStop(); } }
private void EncButton_Click(object sender, EventArgs e) { if (InputRichTextBox.Text == "") { MessageBox.Show("Окно для ввода текста пусто"); } else if (KeyTB.TextLength < 5 || KeyTB.TextLength > 256) { MessageBox.Show("Размер ключа должен находиться в пределах от 5 до 256 символов"); } else { TimeStart(); OutputRichTextBox.Clear(); short[] key = new short[KeyTB.TextLength]; for (int i = 0; i < KeyTB.TextLength; i++) { key[i] = (short)KeyTB.Text[i]; } Algorithm_RC4.AlgorithmRC4 encoder = new Algorithm_RC4.AlgorithmRC4(key); string testString = InputRichTextBox.Text; short[] testBytes = new short[InputRichTextBox.TextLength]; for (int i = 0; i < InputRichTextBox.TextLength; i++) { testBytes[i] = (short)InputRichTextBox.Text[i]; } short[] result = encoder.Encode(testBytes, testBytes.Length); for (int i = 0; i < result.Length; i++) { OutputRichTextBox.Text += (char)result[i]; } TimeStop(); } }