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 test_go_back_through_alphabet(self): expected = 'Y' actual = alphabet.go_backwards('Z') self.assertEquals(expected, actual) expected = 'B' actual = alphabet.go_backwards('C') self.assertEquals(expected, actual) expected = 'H' actual = alphabet.go_backwards('I') self.assertEquals(expected, actual) expected = 'Z' actual = alphabet.go_backwards('A') self.assertEquals(expected, actual) expected = 'W' actual = alphabet.go_backwards('A', 4) self.assertEquals(expected, actual) expected = 'L' actual = alphabet.go_backwards('W', 11) self.assertEquals(expected, actual) expected = 'A' actual = alphabet.go_backwards('A', 0) self.assertEquals(expected, actual)
def decipher(self, encipheredLetter): # get position of letter taking into account the current position of the rotor decipheredLetterIndex = self.getPositionOfLetter(encipheredLetter) decipheredLetter = alphabet.to_letter(decipheredLetterIndex) # WriteOutput(encipheredLetter) # WriteOutput(decipheredLetter) # re-adjust output for any offset if self.getCurrentPosition() > 0: decipheredLetter = alphabet.go_backwards(decipheredLetter, self.getCurrentPosition()) return decipheredLetter
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 getAdjustedNotch(self): return alphabet.go_backwards(self.getNotch(), self.getRingSetting())