Exemplo n.º 1
0
        public void PreExecution()
        {
            isrunning = true;

            running = false;
            stopped = false;

            if (enigmaPresentationFrame.EnigmaPresentation.checkReady())
            {
                enigmaPresentationFrame.EnigmaPresentation.stopclick(this, EventArgs.Empty);
            }
            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs("Preparing enigma for operation..", this, NotificationLevel.Info));

            if (settings.Model != 3 && settings.Model != 2)
            {
                EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs("This simulator is work in progress. As of right now only Enigma I and Enigma Reichsbahn (Rocket) is supported!!", this, NotificationLevel.Warning));
                return;
            }

            // remember the current key-setting, in order to restore on stop
            savedKey = settings.Key;

            //configure the enigma
            core.setInternalConfig(settings.Rotor1, settings.Rotor2, settings.Rotor3, settings.Rotor4,
                                   settings.Reflector, settings.Ring1, settings.Ring2, settings.Ring3, settings.Ring4,
                                   settings.PlugBoard);
        }
Exemplo n.º 2
0
        private const int maxAnalysisEntries = 10; // should go in settings under "Analysis Options"

        #endregion

        #region Private member methods

        /// <summary>
        /// This method basically brute-forces all possible rotors
        /// </summary>
        /// <param name="text">The ciphertext</param>
        private void analyzeRotors(string text)
        {
            // Start the stopwatch
            Stopwatch sw     = Stopwatch.StartNew();
            int       trials = 0;

            for (int i = 0; i < 8; i++)
            {
                //Rotor 3 (slowest)
                if (!includeRotor(i))
                {
                    continue;
                }
                settings.Rotor3 = i;
                for (int j = 0; j < 8; j++)
                {
                    // Rotor 2 (middle)
                    if (!includeRotor(j) || j == i)
                    {
                        continue;
                    }
                    settings.Rotor2 = j;

                    for (int k = 0; k < 8; k++)
                    {
                        // Rotor 1 (fastest)
                        if (!includeRotor(k) || k == i || k == j)
                        {
                            continue;
                        }
                        settings.Rotor1 = k;

                        //set the internal Config to the new rotors
                        core.setInternalConfig(k, j, i, 0, settings.Reflector,
                                               settings.AnalyzeRings ? 1 : settings.Ring1,
                                               settings.AnalyzeRings ? 1 : settings.Ring2,
                                               settings.AnalyzeRings ? 1 : settings.Ring3,
                                               settings.Ring4,
                                               settings.AnalyzePlugs ? settings.Alphabet : settings.PlugBoard);

                        analyzeKeys(text);
                        trials++;

                        pluginFacade.ShowProgress(i * Math.Pow(8, 2) + j * 8 + k, Math.Pow(8, 3));

                        if (stop)
                        {
                            break;
                        }
                    } // Rotor 1
                    if (stop)
                    {
                        break;
                    }
                } // Rotor 2
                if (stop)
                {
                    break;
                }
            } // Rotor 3

            // Stop the stopwatch
            sw.Stop();

            string msg = String.Format("Processed {0} rotor permutations in {1}!",
                                       trials, sw.Elapsed.ToString());

            pluginFacade.LogMessage(msg, NotificationLevel.Info);
        }