コード例 #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);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string     response = "(IbOb~eSGTM~jSdmW~OReSs~hoZhi~cs.!K~(pn!l~-rx;dn~?!))v~6hcGA~y?(Ek~G)4J,~Lls(P~C1BHL~V6QY~-z l/";
            Decryption test = new Decryption();
            int        r1 = 19, r2 = 59, r3 = 37, r4 = 7;

            response = test.DecryptText(response, r1, r2, r3, r4);
            Console.WriteLine(response);
            Console.ReadLine();
        }