Example #1
0
    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)
Example #2
0
 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
Example #3
0
 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))
Example #4
0
 def getAdjustedNotchPosition(self):
     return alphabet.to_letter_index(self.getAdjustedNotch())
Example #5
0
 def setRingSetting(self, setting):
     if str(setting).isdigit():
         self.ringSetting = setting
     else:
         self.setRingSetting(alphabet.to_letter_index(setting))
Example #6
0
 def reflect(self, entryLetter):
     letterIndex = alphabet.to_letter_index(entryLetter)
     return self.wiring[letterIndex];