Esempio n. 1
0
 private void btn_encrypt_Click(object sender, EventArgs e)
 {
     Output.Output            output  = new Output.Output();
     Encrypt.Encrypt          encrypt = new Encrypt.Encrypt();
     Encrypt.EncryptedPackage package = new Encrypt.EncryptedPackage();
     if (File_Upload.Checked)                  // if its a file upload it will pass the file name otherwise the file name is null
     {
         try
         {
             package = encrypt.EncyptText(response);
             output.Textorfile(package.text, package.key, "file", filename);
             File.Delete(OriginalFileName);
             response = null;
             MessageBox.Show("Your text has been encrypted successfuly and the uploaded file has been deleted", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch
         {
             MessageBox.Show("Your text has not been encrypted because an error has occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         try
         {
             response = Input_textbox.Text;
             response = response.Replace("\r\n", null);
             package  = encrypt.EncyptText(response);
             output.Textorfile(package.text, package.key, "textbox", null);
         }
         catch
         {
             MessageBox.Show("Your text has not been encrypted because an error has occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string response = "Hi my ~name is jacob ouellet. I live in Raymond NH, and I am a CIS major at MCC.";

            Encrypt          test = new Encrypt();
            EncryptedPackage x    = new EncryptedPackage();

            x = test.EncyptText(response);
            Console.WriteLine(x.key);
            Console.WriteLine(x.text);
            Console.ReadLine();
        }
Esempio n. 3
0
        public EncryptedPackage EncyptText(string textin)
        {
            string key           = BuildRotorEncrypt();
            string EncryptedText = null;
            char   EncryptedChar;

            char[] Character = textin.ToCharArray();
            for (int i = Character.Length; i > 0; i--)
            {
                int charIndex = GetInitialPosition(Character[count], BuildRotors.Static);
                count++;
                charIndex += x;
                if (charIndex >= 75)
                {
                    charIndex -= 75;
                }
                if (x == 75)
                {
                    x  = 0;
                    y += 1;
                    if (y == 75)
                    {
                        y  = 0;
                        z += 1;
                        if (z == 75)
                        {
                            z  = 0;
                            w += 1;
                            if (w == 75)
                            {
                                w = 0;
                            }
                        }
                    }
                }
                EncryptedChar  = GetRotorIndex(charIndex, BuildRotors.r1);
                EncryptedChar  = Rotater(y, EncryptedChar, charIndex, BuildRotors.r2);
                EncryptedChar  = Rotater(z, EncryptedChar, charIndex, BuildRotors.r3);
                EncryptedChar  = Rotater(w, EncryptedChar, charIndex, BuildRotors.r4);
                EncryptedText += EncryptedChar;
                // review what happens in rotator 2 and then do rotator 3 and four
                x++;
            }
            EncryptedPackage package = new EncryptedPackage();

            package.Set(EncryptedText, key);
            return(package);
        }