def test_to_letter_index(self): expected = 0 actual = alphabet.to_letter_index('A') self.assertEquals(expected, actual) expected = 1 actual = alphabet.to_letter_index('B') self.assertEquals(expected, actual) expected = 25 actual = alphabet.to_letter_index('Z') self.assertEquals(expected, actual)
def encipher(self, clearCharacter): letterIndex = alphabet.to_letter_index(clearCharacter) # encipher the character taking into account the current position of the rotor encipheredCharacter = self.getLetterAtPosition(letterIndex) print("\renciphering: " + clearCharacter) print("\r" + self.wiring) print("enciphered as: " + encipheredCharacter + "\r") # take care of the offset if self.getCurrentPosition() > 0: letterIndex = alphabet.to_letter_index(encipheredCharacter) letterIndex = alphabet.go_backwards(letterIndex, self.getCurrentPosition()) encipheredCharacter = alphabet.to_letter(letterIndex) print("\r offset to :" + encipheredCharacter) return encipheredCharacter
def setCurrentPosition(self, position): currentLetter = "" if str(position).isdigit(): self.currentPosition = position else: currentLetter = alphabet.go_backwards(position, self.getRingSetting()) self.setCurrentPosition(alphabet.to_letter_index(currentLetter))
def getAdjustedNotchPosition(self): return alphabet.to_letter_index(self.getAdjustedNotch())
def setRingSetting(self, setting): if str(setting).isdigit(): self.ringSetting = setting else: self.setRingSetting(alphabet.to_letter_index(setting))
def reflect(self, entryLetter): letterIndex = alphabet.to_letter_index(entryLetter) return self.wiring[letterIndex];