changeset 11:845896830342

Added a simple cipher test using data from Wikipedia.
author Brian Neal <bgneal@gmail.com>
date Sat, 26 May 2012 23:14:23 -0500
parents 9ca7c7a93fc2
children 42858648f8b5
files enigma/tests/test_enigma.py
diffstat 1 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)