Esempio n. 1
0
 private void logMessage(string msg, NotificationLevel lvl)
 {
     if ((int)lvl >= ((int)VerboseLevel - 1))
     {
         pluginFacade.LogMessage(msg, lvl);
     }
 }
Esempio 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);
        }