Пример #1
0
        static void Main(string[] args)
        {
            EnigmaMachine  machine   = new EnigmaMachine();
            EnigmaSettings eSettings = new EnigmaSettings();

            querySettings(eSettings);

            string message = "";

            Console.Write("Enter message to encrypt: ");
            message = Console.ReadLine();
            while (!Regex.IsMatch(message, @"^[a-zA-Z ]+$"))
            {
                Console.Write("Only letters A-Z is allowed, try again: ");
                message = Console.ReadLine();
            }
            message = message.Replace(" ", "").ToUpper();

            // Enter settings on machine
            machine.setSettings(eSettings.rings, eSettings.grund, eSettings.order, eSettings.reflector);

            // The plugboard settings
            foreach (string plug in eSettings.plugs)
            {
                char[] p = plug.ToCharArray();
                machine.addPlug(p[0], p[1]);
            }

            // Message encrypt
            Console.WriteLine();
            Console.WriteLine("Plain text:\t" + message);
            string enc = machine.runEnigma(message);

            Console.WriteLine("Encrypted:\t" + enc);

            // Reset the settings before decrypting!
            machine.setSettings(eSettings.rings, eSettings.grund, eSettings.order, eSettings.reflector);

            // Message decrypt
            string dec = machine.runEnigma(enc);

            Console.WriteLine("Decrypted:\t" + dec);
            Console.WriteLine();

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            EnigmaMachine machine = new EnigmaMachine();
            EnigmaSettings eSettings = new EnigmaSettings();

            querySettings(eSettings);

            string message = "";
            Console.Write("Enter message to encrypt: ");
            message = Console.ReadLine();
            while (!Regex.IsMatch(message, @"^[a-zA-Z ]+$")) {
                Console.Write("Only letters A-Z is allowed, try again: ");
                message = Console.ReadLine();
            }
            message = message.Replace(" ", "").ToUpper();

            // Enter settings on machine
            machine.setSettings(eSettings.rings, eSettings.grund, eSettings.order, eSettings.reflector);

            // The plugboard settings
            foreach (string plug in eSettings.plugs) {
                char[] p = plug.ToCharArray();
                machine.addPlug(p[0], p[1]);
            }

            // Message encrypt
            Console.WriteLine();
            Console.WriteLine("Plain text:\t" + message);
            string enc = machine.runEnigma(message);
            Console.WriteLine("Encrypted:\t" + enc);

            // Reset the settings before decrypting!
            machine.setSettings(eSettings.rings, eSettings.grund, eSettings.order, eSettings.reflector);

            // Message decrypt
            string dec = machine.runEnigma(enc);
            Console.WriteLine("Decrypted:\t" + dec);
            Console.WriteLine();

            Console.ReadLine();
        }