Example #1
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    Console.Write("[-] Enter your message: ");
                    string msg = Console.ReadLine();

                    Console.Write("[-] Enter a secure key: ");
                    double key = GetKey(Console.ReadLine());

                    Console.Write("[-] Enter a secure pin: ");
                    double incr = GetKey(Console.ReadLine());

                    Console.Write("\n\n(E)ncrypt\n(D)ecrypt\n[-] Enter an option: ");
                    string option = Console.ReadLine();

                    string output = (option.ToUpper().StartsWith("E")) ? Enigma.Encrypt(msg, key, incr) :
                                    (option.ToUpper().StartsWith("D")) ? Enigma.Decrypt(msg, key, incr) : " ";

                    Console.WriteLine($"\n[+] Output: {output}");
                    Console.WriteLine("\nPress Enter to Continue");
                    Console.ReadLine();
                    Console.WriteLine("+-----------------------+");
                }
                catch { continue; }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            //starting the Enigma with the specified starting position
            var e     = new Enigma(12, 8, 20);
            var newCh = '.';

            while (true)
            {
                DrawUI(newCh);
                ConsoleKeyInfo pressed;
                pressed = Console.ReadKey();
                newCh   = e.Encrypt(pressed.KeyChar);
            }
        }
Example #3
0
        private void InputText_TextChanged(object sender, EventArgs e)
        {
            inputText.TextChanged -= InputText_TextChanged;

            if (inputText.Text != "")
            {
                char[] inputAux = inputText.Text.ToUpper().ToCharArray();
                inputText.Text = "";

                for (int i = 0; i < inputAux.Length; i++)
                {
                    char typedChar = inputAux[i];

                    if (typedChar < 65 || typedChar > 90)
                    {
                        inputAux[i] = ' ';
                    }
                }

                string strAux = new string(inputAux);
                strAux = strAux.Replace(" ", "");

                inputAux           = strAux.ToCharArray();
                plainTextBox.Text += strAux;


                if (inputAux.Length >= 1)
                {
                    for (int i = 0; i < inputAux.Length; i++)
                    {
                        char typedChar = inputAux[i];

                        // Encrypt (send enteredChar - receive encryptedChar)
                        char encryptedChar = enigma.Encrypt(typedChar);

                        encryptedTextBox.Text += encryptedChar;
                    }

                    // Refresh Rotors Position
                    WH1textBox.Text = Convert.ToChar(rotorsPos[0] + 65).ToString();
                    WH2textBox.Text = Convert.ToChar(rotorsPos[1] + 65).ToString();
                    WH3textBox.Text = Convert.ToChar(rotorsPos[2] + 65).ToString();
                    WH4textBox.Text = Convert.ToChar(rotorsPos[3] + 65).ToString();
                }
            }

            inputText.TextChanged += InputText_TextChanged;
        }