# HG changeset patch # User Brian Neal # Date 1338092063 18000 # Node ID 8458968303420af35ca5ac502644db19c6301d80 # Parent 9ca7c7a93fc270ec3f211c4d33176e54fc9e21ef Added a simple cipher test using data from Wikipedia. diff -r 9ca7c7a93fc2 -r 845896830342 enigma/tests/test_enigma.py --- a/enigma/tests/test_enigma.py Sat May 26 21:43:03 2012 -0500 +++ b/enigma/tests/test_enigma.py Sat May 26 23:14:23 2012 -0500 @@ -10,7 +10,7 @@ from ..machine import EnigmaMachine -class EnigmaMachineTestCase(unittest.TestCase): +class SteppingTestCase(unittest.TestCase): def test_double_stepping(self): """Ensure the rotors step realistically by testing for a "double-step" @@ -34,3 +34,30 @@ m.key_press('A') self.assertEqual(m.get_display(), expected) + +class SimpleCipherTestCase(unittest.TestCase): + """This example taken from Wikipedia""" + + PLAIN_TEXT = 'AAAAA' + CIPHER_TEXT = 'BDZGO' + + def setUp(self): + rotors = [] + rotors.append(create_rotor('I')) + rotors.append(create_rotor('II')) + rotors.append(create_rotor('III')) + + reflector = create_reflector('B') + + self.machine = EnigmaMachine(rotors=rotors, reflector=reflector) + self.machine.set_display('AAA') + + def test_simple_encrypt(self): + + cipher_text = self.machine.process_text(self.PLAIN_TEXT) + self.assertEqual(cipher_text, self.CIPHER_TEXT) + + def test_simple_decrypt(self): + + plain_text = self.machine.process_text(self.CIPHER_TEXT) + self.assertEqual(plain_text, self.PLAIN_TEXT)