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(Rotor[] rots, Reflector re, Plugboard plug, RingSetting rings, WindowSetting initWindow)
        {
            //Following WW2 Convention, it is specified Left-Mid-Right
            this.rotors        = rots;
            this.rotorKnockers = new char[] { rotors[LEFT].getKnocker(), rotors[MID].getKnocker(), rotors[RIGHT].getKnocker() };

            this.reflector     = re;
            this.plugboard     = plug;
            this.windowSetting = initWindow;
            this.ringSetting   = rings;
        }
Ejemplo n.º 3
0
        public Enigma(Rotor[] rots, Reflector re, Plugboard plug, RingSetting rings, WindowSetting initWindow)
        {
            //Following WW2 Convention, it is specified Left-Mid-Right
            this.rotors = rots;
            this.rotorKnockers = new char[] { rotors[LEFT].getKnocker(), rotors[MID].getKnocker(), rotors[RIGHT].getKnocker() };

            this.reflector = re;
            this.plugboard = plug;
            this.windowSetting = initWindow;
            this.ringSetting = rings;
        }
Ejemplo n.º 4
0
        /**
         * Get the appropriate offset (always > 0) of the internal rotor core
         * with respect to global 'A' position
         * This offset is influenced by
         * 	i) the ring setting (which stays the same for a given ciphertext, and
         * 	ii) the window value (which updates every time the enigma ticks)
         * @param ringSetting
         * @param windowSetting
         * @param slot
         * @return
         */
        public static int GetOffsetRotorInternal(RingSetting ringSetting, WindowSetting windowSetting, int slot)
        {
            //for easy intuition, we call the global 'A' position the sea level

            int dispRingAboveSea;			//displacement of Ring with respect to global 'A' position
            int dispRotorInternalWrtRing;
            int dispRotorInternalAboveSea;	//always > 0, expressed in mod26

            dispRingAboveSea = 'A' - windowSetting.getWindowValue(slot); 	//if window shows 'C', disp = -2
            dispRotorInternalWrtRing = ringSetting.ringOffset(slot); 		//offset = 4 means internal A is locked to ring's E
            dispRotorInternalAboveSea = (dispRingAboveSea + dispRotorInternalWrtRing + 26) % 26;

            return dispRotorInternalAboveSea;
        }