コード例 #1
0
        public Socket(Rotor[] r, Plugboard p)
        {
            Rotores = r;

            //this.rotorArotar = 0;//CHANGED

            foreach (Rotor rotor in Rotores)
            {
                rotor.AvisoCicloCompleto += EventoCicloCompleto;//Suscripción a evento por cada uno de los rotores
                rotor.AvisoRotacion      += EventoRotacion;
            }

            Plugboard = p;
            Reflector = new Aplicacion("yruhqsldpxngokñmiebfzcwvjat".ToCharArray());
            Log       = new Log();
        }
コード例 #2
0
        private char Encriptar(char c)
        {
            char temp;

            Log.Entries.Add($"Input: {c}");

            c    = Char.ToLower(c);
            temp = c;
            c    = Plugboard.Encriptar(c);

            Log.Entries.Add($"{temp} -> Plugboard -> {c}");

            for (int i = 0; i < Rotores.Length; i++)
            {
                temp = c;
                c    = Rotores[i].Encriptar(c);

                Log.Entries.Add($"{temp} -> Rotor {i+1} -> {c}");
            }

            temp = c;
            c    = Reflector.Encriptar(c);
            Log.Entries.Add($"{temp} -> Reflector -> {c}");

            for (int i = Rotores.Length - 1; i >= 0; i--)
            {
                temp = c;
                c    = Rotores[i].EncriptarInverso(c);

                Log.Entries.Add($"{temp} -> Rotor {i + 1} -> {c}");
            }

            temp = c;
            c    = Plugboard.EncriptarInverso(c);

            Rotores[0].Rotar();

            Log.Entries.Add($"{temp} -> Plugboard -> {c}");
            Log.Entries.Add($"Output: {c}");
            return(c);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: Botvinnik94/Enigma
        public Form1()
        {
            RotorTypes    = new Rotor[3];
            RotorTypes[0] = new RotorI(0);
            RotorTypes[1] = new RotorII(0);
            RotorTypes[2] = new RotorIII(0);

            RotorSelected = new Dictionary <ComboBox, int>(3);

            Offsets = new int[27] {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26
            };

            P = new Plugboard(new Aplicacion("abcdefghijklmnñopqrstuvwxyz".ToCharArray()));

            InitializeComponent();

            cbbRotor1.DataSource      = RotorTypes;
            cbbOffset1.DataSource     = Offsets;
            cbbRotor2.BindingContext  = new BindingContext();
            cbbOffset2.BindingContext = new BindingContext();
            cbbRotor2.DataSource      = RotorTypes;
            cbbOffset2.DataSource     = Offsets;
            cbbRotor3.BindingContext  = new BindingContext();
            cbbOffset3.BindingContext = new BindingContext();
            cbbRotor3.DataSource      = RotorTypes;
            cbbOffset3.DataSource     = Offsets;

            cbbRotor2.SelectedIndex = 1;
            cbbRotor3.SelectedIndex = 2;
            ChangeEnigma();
            RotorSelected.Add(cbbRotor1, cbbRotor1.SelectedIndex);
            RotorSelected.Add(cbbRotor2, cbbRotor2.SelectedIndex);
            RotorSelected.Add(cbbRotor3, cbbRotor3.SelectedIndex);

            Enigma.EncriptacionFinalizada += EventoLogChanged;
            Enigma.EventoRotacionRotor    += EventoRotacion;
        }
コード例 #4
0
 public void ChangePlugboard(Aplicacion f)
 {
     Plugboard = new Plugboard(f);
 }
コード例 #5
0
ファイル: PlugboardView.cs プロジェクト: Botvinnik94/Enigma
        public PlugboardView(Plugboard p)
        {
            P = p;

            InitializeComponent();

            Abecedario = "abcdefghijklmnñopqrstuvwxyz".ToCharArray();

            IntCharCorrespondency = new Dictionary <char, int>(27)
            {
                { 'a', 0 },
                { 'b', 1 },
                { 'c', 2 },
                { 'd', 3 },
                { 'e', 4 },
                { 'f', 5 },
                { 'g', 6 },
                { 'h', 7 },
                { 'i', 8 },
                { 'j', 9 },
                { 'k', 10 },
                { 'l', 11 },
                { 'm', 12 },
                { 'n', 13 },
                { 'ñ', 14 },
                { 'o', 15 },
                { 'p', 16 },
                { 'q', 17 },
                { 'r', 18 },
                { 's', 19 },
                { 't', 20 },
                { 'u', 21 },
                { 'v', 22 },
                { 'w', 23 },
                { 'x', 24 },
                { 'y', 25 },
                { 'z', 26 }
            };

            ComboBoxArray = new ComboBox[] { cbbA, cbbB, cbbC, cbbD, cbbE, cbbF, cbbG, cbbH, cbbI, cbbJ, cbbK, cbbL, cbbM, cbbN, cbbNN, cbbO, cbbP, cbbQ, cbbR,
                                             cbbS, cbbT, cbbU, cbbV, cbbW, cbbX, cbbY, cbbZ };


            FillIndexesSelected();

            cbbA.DataSource      = Abecedario;
            cbbB.BindingContext  = new BindingContext();
            cbbB.DataSource      = Abecedario;
            cbbC.BindingContext  = new BindingContext();
            cbbC.DataSource      = Abecedario;
            cbbD.BindingContext  = new BindingContext();
            cbbD.DataSource      = Abecedario;
            cbbE.BindingContext  = new BindingContext();
            cbbE.DataSource      = Abecedario;
            cbbF.BindingContext  = new BindingContext();
            cbbF.DataSource      = Abecedario;
            cbbG.BindingContext  = new BindingContext();
            cbbG.DataSource      = Abecedario;
            cbbH.BindingContext  = new BindingContext();
            cbbH.DataSource      = Abecedario;
            cbbI.BindingContext  = new BindingContext();
            cbbI.DataSource      = Abecedario;
            cbbJ.BindingContext  = new BindingContext();
            cbbJ.DataSource      = Abecedario;
            cbbK.BindingContext  = new BindingContext();
            cbbK.DataSource      = Abecedario;
            cbbL.BindingContext  = new BindingContext();
            cbbL.DataSource      = Abecedario;
            cbbM.BindingContext  = new BindingContext();
            cbbM.DataSource      = Abecedario;
            cbbN.BindingContext  = new BindingContext();
            cbbN.DataSource      = Abecedario;
            cbbNN.BindingContext = new BindingContext();
            cbbNN.DataSource     = Abecedario;
            cbbO.BindingContext  = new BindingContext();
            cbbO.DataSource      = Abecedario;
            cbbP.BindingContext  = new BindingContext();
            cbbP.DataSource      = Abecedario;
            cbbQ.BindingContext  = new BindingContext();
            cbbQ.DataSource      = Abecedario;
            cbbR.BindingContext  = new BindingContext();
            cbbR.DataSource      = Abecedario;
            cbbS.BindingContext  = new BindingContext();
            cbbS.DataSource      = Abecedario;
            cbbT.BindingContext  = new BindingContext();
            cbbT.DataSource      = Abecedario;
            cbbU.BindingContext  = new BindingContext();
            cbbU.DataSource      = Abecedario;
            cbbV.BindingContext  = new BindingContext();
            cbbV.DataSource      = Abecedario;
            cbbW.BindingContext  = new BindingContext();
            cbbW.DataSource      = Abecedario;
            cbbX.BindingContext  = new BindingContext();
            cbbX.DataSource      = Abecedario;
            cbbY.BindingContext  = new BindingContext();
            cbbY.DataSource      = Abecedario;
            cbbZ.BindingContext  = new BindingContext();
            cbbZ.DataSource      = Abecedario;

            UpdateComboBoxes();

            finishedLoading = true;
        }