Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Rotor rL = new Rotor(FixedMechanicRotor.ROTOR_II);  //II has notch F
            Rotor rM = new Rotor(FixedMechanicRotor.ROTOR_IV);  //IV has notch K
            Rotor rR = new Rotor(FixedMechanicRotor.ROTOR_V);   //V  has notch A

            //Following WW2 Convention, it is Left-Mid-Right e.g. II IV V
            Rotor[] rotors = { rL, rM, rR };


            Reflector re   = new Reflector(FixedMechanicReflector.REFLECTOR_B);
            Plugboard plug = new Plugboard(new String[] {
                "AV", "BS", "CG", "DL", "FU", "HZ", "IN", "KM", "OW", "RX"
            });                                                                               //Barbarosa
            WindowSetting initialSetting = new WindowSetting('B', 'L', 'A');
            RingSetting   ringPositions  = new RingSetting(2, 21, 12);



            //an example of naming hassle because Enigma is both namespace and class
            Enigma.representation.Enigma enigma = new Enigma.representation.Enigma(rotors, re, plug, ringPositions, initialSetting);



            string myfile = "C:\\Users\\ToshiW\\Documents\\Visual Studio 2012\\Projects\\Enigma\\Enigma\\Resources\\BarbarosaCiphertext.txt";
            string input  = Utility.FileToString(myfile);
            //Console.WriteLine(readResult);
            //Console.ReadLine();

            //Let Enigma do its thing
            string result = enigma.encryptString(input);

            Console.WriteLine(result);
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public Enigma
            (int enigmaModel, int reflectorType,
            int wh4, int wh3, int wh2, int wh1,
            char rs4, char rs3, char rs2, char rs1,
            char ws4, char ws3, char ws2, char ws1,
            ref int[] plugs, ref int[] rotorsPos
            )
        {
            this.enigmaModel = enigmaModel;

            // Rotors
            rotor4 = new RotorM4(wh4, rs4, ws4);
            rotor3 = new RotorM3(wh3, rs3, ws3);
            rotor2 = new RotorM3(wh2, rs2, ws2);
            rotor1 = new RotorM3(wh1, rs1, ws1);

            // Reflector
            reflectorType += (enigmaModel == 1 ? 2 : 0);
            reflector      = new Reflector(reflectorType);

            // Plugboard
            plugboard = new Plugboard(ref plugs);

            this.rotorsPos = rotorsPos;
        }
Ejemplo n.º 3
0
        public EnigmaMachine()
        {
            //转子对应规则
            rotors = new Rotor[] {
                new Rotor(new int[] { 18, 25, 4, 24, 1, 2, 14, 10, 0, 11, 12, 8, 3, 20, 23, 7, 16, 21, 13, 15, 5, 22, 9, 17, 19, 6 }),
                new Rotor(new int[] { 7, 25, 2, 24, 11, 10, 13, 12, 9, 20, 16, 22, 6, 5, 4, 15, 19, 14, 23, 1, 0, 17, 21, 3, 18, 8 }),
                new Rotor(new int[] { 21, 9, 3, 19, 22, 13, 11, 15, 10, 2, 17, 18, 23, 12, 6, 16, 4, 0, 7, 8, 14, 5, 24, 25, 1, 20 }),
                new Rotor(new int[] { 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 })
            };
            //默认转子
            rotor1 = rotors[0];
            rotor2 = rotors[1];
            rotor3 = rotors[2];
            //默认反射板
            reflector = new Reflector(new int[] { 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 });
            //连线板
            plugboard = new Plugboard();

            alphaToNumber = new Dictionary <char, int>();
            foreach (char letter in alphabet)
            {
                alphaToNumber[letter] = alphabet.IndexOf(letter);
            }

            rotorPosition = 0;
            prevLength    = 0;
        }
Ejemplo n.º 4
0
 // cinstructor
 public Enigma(Rotor R1, Rotor R2, Rotor R3, Plugboard P, Reflector Ref)
 {
     Rotor1    = R1;
     Rotor2    = R2;
     Rotor3    = R3;
     Plugboard = P;
     Reflector = Ref;
 }
Ejemplo n.º 5
0
 public EnigmaMachine(Scrambler[] scramblers, Reflector reflector, Plugboard plugboard)
 {
     this.scramblers = scramblers;
     this.reflector  = reflector;
     this.plugboard  = plugboard;
 }
 public EnigmaMachine()
 {
     _plugboard = new Plugboard();
     _reflector = new Reflector();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates Engima plugboard from cipher.
 /// </summary>
 /// <param name="cipher">Cipher that defines plugboard connections.</param>
 private static void BuildPlugboard(int[] cipher = null)
 {
     int[] defaultCipher = { 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 };
     _plugboard = new Plugboard(cipher ?? defaultCipher);
 }
Ejemplo n.º 8
0
 public void InsertPlugboard(Plugboard plugboard)
 {
     this.Plugboard = plugboard;
     Disc.Connect(Rotors.Last().RightDisc, this.Plugboard.LeftDisc);
 }