Cédric Bonhomme avatar Cédric Bonhomme committed 6da10b5

bugfix: pretty display of enigma machine + updated readme

Comments (0)

Files changed (3)

     Python 3.2.3 (default, Oct 19 2012, 19:53:16) 
     [GCC 4.7.2] on linux2
     Type "help", "copyright", "credits" or "license" for more information.
-    >>> from pyenigma import rotor
-    >>> print(rotor.ROTOR_GR_III)
+    >>> from pyenigma.enigma import *
+    >>> from pyenigma.rotor import *
+    >>> print(ROTOR_GR_III)
 
         Name: III
         Model: German Railway (Rocket)
         Date: 7 February 1941
         Wiring: JVIUBHTCDYAKEQZPOSGXNRMWFL
     >>>
+    >>> engr = Enigma(ROTOR_Reflector_A, ROTOR_I, ROTOR_II, ROTOR_III, key="ABC")
+    >>> print(engr)
+
+        Reflector: 
+        Name: Reflector A
+        Model: None
+        Date: None
+        Wiring: EJMZALYXVBWFCRQUONTSPIKHGD
+        Rotor 1: 
+        Name: III
+        Model: Enigma 1
+        Date: 1930
+        Wiring: BDFHJLCPRTXVZNYEIWGAKMUSQO
+        Rotor 2: 
+        Name: II
+        Model: Enigma 1
+        Date: 1930
+        Wiring: AJDKSIRUXBLHWTMCQGZNPYFVOE
+        Rotor 3: 
+        Name: I
+        Model: Enigma 1
+        Date: 1930
+        Wiring: EKMFLGDQVZNTOWYHXUSPAIBRCJ
+    >>> res = engr.encipher("Hellow World!")
+    >>> print(res)
+    Rkmwng Tkuvk!
+
 
 Command line:
 
-    $ echo "Hello World" | ./cypher_enigma_safe.py secret B  I II V 
+    $ echo "Hello World" | ./cypher_enigma_safe.py ABC B  I II IV
     Vjpfw Ekdxj
 
-    $ echo "Vjpfw Ekdxj" | ./cypher_enigma_safe.py secret B  I II V
+    $ echo "Iajfb Sqguz" | ./cypher_enigma_safe.py ABC B  I II IV
     Hello World
 
 License

pyenigma/cypher_enigma_safe.py

 
 def usage():
     print("Usage:")
-    print('\techo "Hello World" | ./cypher_enigma_safe.py key ref rotor1 rotor2 rotor3')
+    print('\techo "Hello World" | ./cypher_enigma_safe.py ABC ref rotor1 rotor2 rotor3')
     print("\nExample:")
-    print('\t$ echo "Hello World" | ./cypher_enigma_safe.py secret B  I II IV')
-    print("\tXtrmk Sfjyu")
+    print('\t$ echo "Hello World" | ./cypher_enigma_safe.py ABC B  I II IV')
+    print("\tIajfb Sqguz")
 
 if __name__ == "__main__":
     # Point of entry in execution mode
           "C":ROTOR_Reflector_C \
           }
 
-    engr = Enigma(reflectors[ref], rotors[r1], rotors[r2], rotors[r3], key)
+    engr = Enigma(reflectors[ref], rotors[r1], rotors[r2], rotors[r3], key=key)
     res = engr.encipher(raw)
     print(res)

pyenigma/enigma.py

     """
     Represents an Enigma machine.
     """
-    def __init__(self, ref, r3, r2, r1, setting='AAA', plugs = [], ringset=1):
+    def __init__(self, ref, r3, r2, r1, key='AAA', ringset=1):
         """
         Initialization of the Enigma machine.
         """
         self.rotor2 = r2
         self.rotor3 = r3
 
-        self.rotor1.state = setting[0]
-        self.rotor2.state = setting[1]
-        self.rotor3.state = setting[2]
+        self.rotor1.state = key[0]
+        self.rotor2.state = key[1]
+        self.rotor3.state = key[2]
         self.reflector.state = 'A'
         self.ringset = ringset
 
         Reflector: %s
         Rotor 1: %s
         Rotor 2: %s
-        Rotor 3: %s""" % (self.reflector, self.r1, self.r2, self.r3)
+        Rotor 3: %s""" % (self.reflector, self.rotor1, self.rotor2, self.rotor3)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.