示例#1
0
        private void btn_Decrypt_Click(object sender, EventArgs e)
        {
            int count = 0;

            Decrypt.Decryption           Decryption = new Decrypt.Decryption();
            Decrypt_Output.OutputDecrypt Output = new Decrypt_Output.OutputDecrypt();
            Utilities.PrimeCheck         checkifprime = new Utilities.PrimeCheck();
            int rotor1, rotor2, rotor3, rotor4;



            rotor1 = int.Parse(comboBox1.Text);   // check for prime
            rotor2 = int.Parse(comboBox2.Text);
            rotor3 = int.Parse(comboBox3.Text);
            rotor4 = int.Parse(comboBox4.Text);

            if (checkifprime.IsPrime(rotor1) && checkifprime.IsPrime(rotor2) && checkifprime.IsPrime(rotor3) && checkifprime.IsPrime(rotor4))
            {
                try                  // gets rotor information if rotor is null the trry catch will catch the error
                {
                    if (File_Upload.Checked)
                    {
                        response = Decryption.DecryptText(response, rotor1, rotor2, rotor3, rotor4);
                        Output.Output("file", response, filename);
                        File.Delete(OriginalFileName);
                        MessageBox.Show("Your text has been decrypted successfuly and the uploaded file has been deleted", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        response = Input_textbox.Text;
                        response = response.Replace("\r\n", null);
                        response = Decryption.DecryptText(response, rotor1, rotor2, rotor3, rotor4);
                        Output.Output("textbox", response, filename);
                    }
                }
                catch
                {
                    if (count == 0)
                    {
                        count++;
                        btn_Decrypt_Click(null, null);
                    }
                    else
                    {
                        MessageBox.Show("Your text has not been decrypted because an error has occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("A rotor selection is empty or a non-prime number has not been entered" +
                                "\n Note! Prime numbers must be between 2-73", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }