Esempio n. 1
0
        private void Encrypt()
        {
            shidden = "";

            //sInput = textBox1.Text.Substring(l, 1);
            i   = Int32.Parse(numericUpDown1.Value.ToString()) - 1;
            ii  = Int32.Parse(numericUpDown2.Value.ToString()) - 1;
            iii = Int32.Parse(numericUpDown3.Value.ToString()) - 1;
            //iv = Int32.Parse(numericUpDown4.Value.ToString()) - 1;

            if (sInput == " ")
            {
                sOutput        = " ";
                textBox2.Text += " ";
                return;
            }
            if (ralpha.IsMatch(sInput) == false)
            {
                sOutput        = sInput;
                textBox2.Text += sOutput;
                return;
            }
            if (steckerbrett[0].Contains(sInput))
            {
                sOutput = steckerbrett[1].Substring(steckerbrett[0].IndexOf(sInput), 1);
                shidden = sInput + "->" + sOutput;
            }
            else if (steckerbrett[1].Contains(sInput))
            {
                sOutput = steckerbrett[0].Substring(steckerbrett[1].IndexOf(sInput), 1);
                shidden = sInput + "->" + sOutput;
            }
            else//Not a plugged character
            {
                shidden = sInput;
                sOutput = sInput;
            }
            Increment_Rotors();//step on typing and before encryption

            sOutput  = rotor3.Encrypt(iii - ringstellung[2], sOutput);
            shidden += sOutput;
            sOutput  = rotor2.Encrypt(ii - iii - ringstellung[1] + ringstellung[2], sOutput);
            shidden += sOutput;
            sOutput  = rotor1.Encrypt(i - ii - ringstellung[0] + ringstellung[1], sOutput);
            shidden += sOutput;

            if (sRotor4 != "")
            {
                sOutput  = rotor4.Encrypt(iv - ringstellung[3], sOutput);
                shidden += sOutput;
            }

            shidden += "<-->";
            sOutput  = reflector1.Encrypt(ringstellung[0] - i, sOutput);
            shidden += sOutput;

            if (sRotor4 != "")
            {
                sOutput  = rotor4.Decrypt(iv - ringstellung[3], sOutput);
                shidden += sOutput;
            }

            sOutput  = rotor1.Decrypt(i - ringstellung[0], sOutput);
            shidden += sOutput;
            sOutput  = rotor2.Decrypt(ii - ringstellung[1], sOutput);
            shidden += sOutput;
            sOutput  = rotor3.Decrypt(iii - ringstellung[2], sOutput);
            shidden += sOutput;

            if (steckerbrett[0].Contains(sOutput))
            {
                sOutput  = steckerbrett[1].Substring(steckerbrett[0].IndexOf(sOutput), 1);
                shidden += sInput + "->" + sOutput;
            }
            else if (steckerbrett[1].Contains(sOutput))
            {
                sOutput  = steckerbrett[0].Substring(steckerbrett[1].IndexOf(sOutput), 1);
                shidden += sInput + "->" + sOutput;
            }

            //numericUpDown4.Value = iv + 1;
            numericUpDown3.Value = iii + 1;
            numericUpDown2.Value = ii + 1;
            numericUpDown1.Value = i + 1;

            pos2           = Array.FindIndex(temp, element => element == sOutput[0]);
            sOutput        = alphabet[pos2].ToString();
            textBox2.Text += sOutput;
            //label33.Text = i.ToString();
            //tbxHidden.Text = shidden;
        }