def test_encrypt_forward_offset_no_ring_setting_nowrap(self): ''' The most basic of forward encrypts where the rotor is in position A and the letter A is pressed. ''' rotor = Rotor('Test', 'EKMFLGDQVZNTOWYHXUSPAIBRCJ', ["Q"], self._logger) rotor.position = RotorContact.C.value self.assertEqual(rotor.encrypt(RotorContact.A), RotorContact.K)
def test_encrypt_backwards_with_offset_no_ring_setting_wrap(self): ''' Verify that on pressing 'Z' (25) we get the encoded value of 'X' (23). Explanation: 'Z' (25) is pressed with a rotor position of 5. The original input is advanced 4 to 'D' which will return the letter 'B'. Because of the position offset the result is adjusted down 4 to return 'X'. ''' rotor = Rotor('Test', 'BDFHJLCPRTXVZNYEIWGAKMUSQO', ["Q"], self._logger) rotor.position = RotorContact.E.value self.assertEqual(rotor.encrypt(RotorContact.Z, forward=False), RotorContact.X)
def test_encrypt_backwards_with_offset_no_ring_setting_nowrap(self): ''' Verify that on pressing 'I' (9) we get the encoded value of 'S' (18). Explanation: 'I' (9) is pressed with a rotor position of 3, the encoded letter that is returned is 'S' (18) because the input is advanced 2 to 'K', which will return the letter 'U'. Because off the 2 position offset we then need to adjust the result down 2 to return 'S'. ''' rotor = Rotor('Test', 'BDFHJLCPRTXVZNYEIWGAKMUSQO', ["Q"], self._logger) rotor.position = RotorContact.C.value self.assertEqual(rotor.encrypt(RotorContact.I, forward=False), RotorContact.S)
def test_encrypt_forward_offset_no_ring_setting_wrap(self): ''' Verify that when key 'S' (18) is pressed when the rotor is rotated 3 positions we get the encoded contact of 'X' (23). Explanation: Key 'S' (18) is pressed, as the rotor is in position 3 (C) this means it goes the wiring circuit of 'U' resulting in an encoded value of 'A'. As the rotor is in position 3 we need to adjust the output by a value of 2, therefore 'Y' is returned. ''' rotor = Rotor('Test', 'EKMFLGDQVZNTOWYHXUSPAIBRCJ', ["Q"], self._logger) rotor.position = RotorContact.C.value self.assertEqual(rotor.encrypt(RotorContact.S), RotorContact.Y)