Esempio n. 1
0
 public Rotor(LetterSet letterSet, int key)
 {
     Key            = key;
     this.letterSet = letterSet;
     InitialOffset  = key - (Base * (Key / Base));
     Offset         = InitialOffset;
 }
Esempio n. 2
0
 public SetupArgs(LetterSet letterSet)
 {
     LetterSet  = letterSet ?? throw new ArgumentNullException(nameof(letterSet));
     Steckering = new int[LetterSet.Count];
     for (int i = 0; i < LetterSet.Count; i++)
     {
         Steckering[i] = i;
     }
 }
 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]));
     }
 }
Esempio n. 4
0
        public char Encipher(char c, bool peek = false)
        {
            int index = LetterSet.IndexOf(c);

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

            index = plugboard.Encipher(index);
            index = rotors.Encipher(index, peek);
            return(LetterSet[index]);
        }
Esempio n. 5
0
 public Plugboard(LetterSet letterSet, int[] steckering)
 {
     this.letterSet  = letterSet ?? throw new ArgumentNullException(nameof(letterSet));
     this.steckering = steckering ?? throw new ArgumentNullException(nameof(steckering));
     if (steckering.Length != letterSet.Count)
     {
         throw new ArgumentException(nameof(steckering));
     }
     reverseSteckering = new int[steckering.Length];
     for (int i = 0; i < steckering.Length; i++)
     {
         reverseSteckering[i] = Array.IndexOf(steckering, i);
     }
 }