/// <summary>
        /// Runs the plugboard randomizer.
        /// </summary>
        ///
        /// <exception cref="IOException">
        /// The input save path is invalid.
        /// </exception>
        /// <exception cref="SaveFailedException">
        /// Failed to save the new plugboard steckering.
        /// </exception>
        public void RandomizePlugboard(LetterSet letterSet, string input)
        {
            if (letterSet == null)
            {
                throw new LetterSetMissingException("Cannot configure Plugboard without a loaded letterset!");
            }
            string file = input;

            try {
                Path.GetFullPath(file);
                string directory = Path.GetDirectoryName(file);
                if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
            } catch (Exception ex) {
                throw new IOException($"Input file \"{file}\" has an invalid path!\n" + ex.Message, ex);
            }
            try {
                Steckering newSteckering = letterSet.RandomizeSteckering();
                SaveToFile(letterSet, newSteckering, file);
                Steckering = newSteckering;
                File       = file;
            }
            catch (Exception ex) {
                throw new SaveFailedException(ex);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Runs the plugboard randomizer.
 /// </summary>
 ///
 /// <exception cref="SaveFailedException">
 /// Failed to save the new plugboard steckering.
 /// </exception>
 public void RandomizePlugboard(LetterSet letterSet)
 {
     if (letterSet == null)
     {
         throw new LetterSetMissingException("Cannot configure Plugboard without a loaded letterset!");
     }
     try {
         Steckering newSteckering = letterSet.RandomizeSteckering();
         SaveToFile(letterSet, newSteckering, File);
         Steckering = newSteckering;
     }
     catch (Exception ex) {
         throw new SaveFailedException(ex);
     }
 }
Esempio n. 3
0
        public EnigmaService()
        {
            char[] letters = new char[127 - 32 + 1];
            for (int i = 0; i < 127 - 32; i++)
            {
                letters[i] = (char)(i + 32);
            }
            letters[letters.Length - 1] = '\n';
            LetterSet letterSet = new LetterSet(letters);

            setup = new SetupArgs(letterSet)
            {
                Steckering       = letterSet.RandomizeSteckering(),
                InvalidCharacter = '?',
                ResetAfter       = 50,
                RotorCount       = 3,
                RotateOnInvalid  = true,
                UnmappedHandling = UnmappedHandling.Keep,
            };
        }