You are on page 1of 2

namespace sheldor { public partial class sheldor : Form { bool flaga; bool flagb; public sheldor() { InitializeComponent(); flaga

= false; flagb = false; } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("Welcome to Encryption/Decryption Software", "Wecome "); } private void textBox1_TextChanged(object sender, EventArgs e) //Plaintex t1 { if (flaga == false) { flaga = true; plaintext1.Text = ""; } } private void textBox3_TextChanged(object sender, EventArgs e) //Cipherte xt2 { if (flagb == false) { flagb = true; ciphertext2.Text = ""; } } private void button1_Click(object sender, EventArgs e) //Encipher { DialogResult result = MessageBox.Show("This may take a while, do you wish to continue ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclama tion); if (result == System.Windows.Forms.DialogResult.Yes) { string ch = plaintext1.Text; int p = ch.Length; int[] s = new int[p]; for (int i = 0; i < p; i++) { if ((int)(ch[i]) <= 128) { s[i] = (int)(ch[i]) + 128; } else if (((int)(ch[i]) > 128) && ((int)(ch[i]) <= 255)) { s[i] = (int)(ch[i]) - 128; } } ciphertext1.Text = ""; for (int i = 0; i < p; i++) { ciphertext1.Text += Convert.ToChar(s[i]);

} MessageBox.Show("Encryption complete."); flaga = false; } } private void button2_Click(object sender, EventArgs e) //decipher { DialogResult result = MessageBox.Show("This may take a while, do you wish to continue ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclama tion); if (result == System.Windows.Forms.DialogResult.Yes) { string ch = ciphertext2.Text; int p = ch.Length; int[] s = new int[p]; for (int i = 0; i < p; i++) { if ((int)(ch[i]) <= 128) { s[i] = (int)(ch[i]) + 128; } else if (((int)(ch[i]) > 128) && ((int)(ch[i]) <= 255)) { s[i] = (int)(ch[i]) - 128; } } plaintext2.Text = ""; for (int i = 0; i < p; i++) { plaintext2.Text += Convert.ToChar(s[i]); } MessageBox.Show("Decryption complete."); flagb = false; } } } }

You might also like