Exemplo n.º 1
0
        public char Encode(char character)
        {
            var offsetedCharacter = AlphabetHelper.GetNextChar(character, GetOffset());
            var mappedCharacter   = Mapping[offsetedCharacter];

            return(AlphabetHelper.GetNextChar(mappedCharacter, GetInverseOffset()));
        }
Exemplo n.º 2
0
        public char InverseEncode(char character)
        {
            var offsetedCharacter = AlphabetHelper.GetNextChar(character, GetOffset());
            var mappedCharacter   = Mapping.Where(x => x.Value == offsetedCharacter).FirstOrDefault().Key;

            return(AlphabetHelper.GetNextChar(mappedCharacter, GetInverseOffset()));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Move the rotor to the next letter. If the current letter is the notch letter, the next rotor has to me move
        /// </summary>
        /// <returns>True if the next rotor has to be moved, false if hasn't </returns>
        public bool MoveRotor()
        {
            var moveNextRotor = TurnOverNotchLetter == CurrentLetter;

            CurrentLetter = AlphabetHelper.GetNextChar(CurrentLetter);
            return(moveNextRotor);
        }
Exemplo n.º 4
0
        private Reflector(string code, string mapping)
        {
            Code    = code;
            Mapping = new Dictionary <char, char>();
            var alphabet = AlphabetHelper.GetAlphabet().ToList();

            for (int idx = 0; idx < 26; idx++)
            {
                Mapping[alphabet[idx]] = mapping[idx];
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create the rotor with the given configuration
        /// </summary>
        /// <param name="code"></param>
        /// <param name="turnOverNotchLetter"></param>
        /// <param name="mapping"></param>
        /// <param name="startingLetter"></param>
        private Rotor(string code, char turnOverNotchLetter, string mapping, char startingLetter)
        {
            Code = code;
            TurnOverNotchLetter = turnOverNotchLetter;
            StartingLetter      = startingLetter;
            CurrentLetter       = startingLetter;
            Mapping             = new Dictionary <char, char>();
            var alphabet = AlphabetHelper.GetAlphabet().ToList();

            for (int idx = 0; idx < 26; idx++)
            {
                Mapping[alphabet[idx]] = mapping[idx];
            }
        }