public char Encode(char character) { var offsetedCharacter = AlphabetHelper.GetNextChar(character, GetOffset()); var mappedCharacter = Mapping[offsetedCharacter]; return(AlphabetHelper.GetNextChar(mappedCharacter, GetInverseOffset())); }
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())); }
/// <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); }
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]; } }
/// <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]; } }