private void button1_Click(object sender, EventArgs e) { if ((textBox2.Text.Length < 1) || (textBox2.Text.Length > 129)) { System.Windows.Forms.MessageBox.Show("Text must consist of 1 to 129 characters"); } else if (textBox1.Text.Length < 1) { System.Windows.Forms.MessageBox.Show("Password cannot be empty string"); } else { string password = textBox1.Text; string text = textBox2.Text; BigInteger plaintext = new BigInteger(Encoding.ASCII.GetBytes(text)); Cursor.Current = Cursors.WaitCursor; maintext = BigIntegerExtensions.Encrypt(plaintext, password, 128); string encryptedText = new string(Encoding.ASCII.GetChars(maintext.ToByteArray())); if (encryptedText.Length > 129) { System.Windows.Forms.MessageBox.Show("Failed to encrypt message with that password. Try changing your password or message."); maintext = new BigInteger(Encoding.ASCII.GetBytes(textBox2.Text)); } else { textBox2.Text = encryptedText; } Cursor.Current = Cursors.Default; } }
private void button2_Click(object sender, EventArgs e) { if ((textBox2.Text.Length < 1) || (textBox2.Text.Length > 129)) { System.Windows.Forms.MessageBox.Show("Text must consist of 1 to 128 characters"); } else if (textBox1.Text.Length < 1) { System.Windows.Forms.MessageBox.Show("Password cannot be empty string"); } else { string password = textBox1.Text; Cursor.Current = Cursors.WaitCursor; maintext = BigIntegerExtensions.Decrypt(maintext, password, 128); textBox2.Text = new string(Encoding.ASCII.GetChars(maintext.ToByteArray())); Cursor.Current = Cursors.Default; } }