def test_to_letter(self): expected = 'A' actual = alphabet.to_letter(0) self.assertEquals(expected, actual) expected = 'M' actual = alphabet.to_letter(12) self.assertEquals(expected, actual) expected = 'Z' actual = alphabet.to_letter(25) 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 getIndicator(self): currentLetter = alphabet.to_letter(self.getCurrentPosition()) return alphabet.go_forwards(currentLetter, self.getRingSetting()).upper() def getWiring(self): return self.wiring