Пример #1
0
 public Rotor(LetterSet letterSet, int key)
 {
     Key            = key;
     this.letterSet = letterSet;
     InitialOffset  = key - (Base * (Key / Base));
     Offset         = InitialOffset;
 }
Пример #2
0
 /// <summary>
 /// Constructs a <see cref="SetupArgs"/> with the specified letterset.
 /// </summary>
 /// <param name="letterSet">The letterset to use.</param>
 public SetupArgs(LetterSet letterSet)
 {
     LetterSet = letterSet ?? throw new ArgumentNullException(nameof(letterSet));
     int[] steckering = new int[LetterSet.Count];
     for (int i = 0; i < LetterSet.Count; i++)
     {
         steckering[i] = i;
     }
     Steckering = new Steckering(steckering);
 }
Пример #3
0
 public RotorCollection(LetterSet letterSet, int rotorCount)
 {
     if (rotorCount < 1)
     {
         throw new ArgumentException(nameof(rotorCount));
     }
     this.letterSet = letterSet ?? throw new ArgumentNullException(nameof(letterSet));
     rotors         = new List <Rotor>();
     for (int i = 0; i < rotorCount; i++)
     {
         rotors.Add(new Rotor(letterSet, PrimeNumbers[i]));
     }
 }
Пример #4
0
        /// <summary>
        /// Deciphers the specified character.
        /// </summary>
        /// <param name="c">The character to decipher.</param>
        /// <param name="peek">True if the rotors should not be rotated.</param>
        /// <returns>The deciphered character.</returns>
        public char Decipher(char c, bool peek = false)
        {
            int index = LetterSet.IndexOf(c);

            if (index == -1)
            {
                return(HandleInvalid(c, peek));
            }

            index = rotors.Decipher(index, peek);
            index = plugboard.Decipher(index);
            return(LetterSet[index]);
        }
Пример #5
0
        //private readonly Steckering reverseSteckering;

        #endregion

        #region Constructors

        /// <summary>
        /// Constructs the <see cref="Plugboard"/>.
        /// </summary>
        /// <param name="letterSet">The letterset to compare to the steckering.</param>
        /// <param name="steckering">The steckering to use.</param>
        public Plugboard(LetterSet letterSet, Steckering steckering)
        {
            if (letterSet == null)
            {
                throw new ArgumentNullException(nameof(letterSet));
            }
            this.steckering = steckering ?? throw new ArgumentNullException(nameof(steckering));
            if (steckering.Count != letterSet.Count)
            {
                throw new ArgumentException(nameof(steckering));
            }
            //reverseSteckering = steckering.Reverse();
        }
Пример #6
0
 /// <summary>
 /// Constructs the <see cref="Plugboard"/>.
 /// </summary>
 /// <param name="letterSet">The letterset to compare to the steckering.</param>
 /// <param name="steckering">The steckering to use.</param>
 public Plugboard(LetterSet letterSet, Steckering steckering)
 {
     if (letterSet == null)
     {
         throw new ArgumentNullException(nameof(letterSet));
     }
     this.steckering = steckering ?? throw new ArgumentNullException(nameof(steckering));
     if (steckering.Count != letterSet.Count)
     {
         throw new ArgumentException($"Letterset and Steckering count do not match!\n" +
                                     $"Letterset: {letterSet.Count}, Steckering: {steckering.Count}",
                                     nameof(steckering));
     }
 }
Пример #7
0
        public Plugboard(LetterSet letterSet, Steckering steckering)
        {
            this.letterSet  = letterSet ?? throw new ArgumentNullException(nameof(letterSet));
            this.steckering = steckering ?? throw new ArgumentNullException(nameof(steckering));
            if (steckering.Count != letterSet.Count)
            {
                throw new ArgumentException(nameof(steckering));
            }
            reverseSteckering = steckering.Reverse();

            /*reverseSteckering = new int[steckering.Length];
             * for (int i = 0; i < steckering.Length; i++) {
             *      reverseSteckering[i] = Array.IndexOf(steckering, i);
             * }*/
        }
Пример #8
0
 /// <summary>
 /// Constructs the <see cref="RotorCollection"/>.
 /// </summary>
 /// <param name="letterSet">The letterset used by the rotors for calculation.</param>
 /// <param name="rotorCount">The number of rotors to use.</param>
 public RotorCollection(LetterSet letterSet, int rotorCount)
 {
     if (rotorCount < 1)
     {
         throw new ArgumentException(nameof(rotorCount));
     }
     if (letterSet == null)
     {
         throw new ArgumentNullException(nameof(letterSet));
     }
     rotors = new Rotor[rotorCount];
     for (int i = 0; i < rotorCount; i++)
     {
         rotors[i] = new Rotor(letterSet, PrimeNumbers[i]);
     }
 }
Пример #9
0
 /// <summary>
 /// Constructs the <see cref="RotorCollection"/>.
 /// </summary>
 /// <param name="letterSet">The letterset used by the rotors for calculation.</param>
 /// <param name="rotorKeys">
 /// The list of prime number keys describing the offset and number of rotors.
 /// </param>
 public RotorCollection(LetterSet letterSet, RotorKeys rotorKeys, bool rotateRotors)
 {
     if (letterSet == null)
     {
         throw new ArgumentNullException(nameof(letterSet));
     }
     if (rotorKeys == null)
     {
         throw new ArgumentNullException(nameof(rotorKeys));
     }
     rotors = new Rotor[rotorKeys.Count];
     for (int i = 0; i < rotorKeys.Count; i++)
     {
         rotors[i] = new Rotor(letterSet, rotorKeys[i]);
     }
     this.rotateRotors = rotateRotors;
 }