Commits

Cédric Bonhomme committed 722b04b

Updated README.

Comments (0)

Files changed (3)

         Date: 7 February 1941
         Wiring: JVIUBHTCDYAKEQZPOSGXNRMWFL
     >>>
-    >>> engr = enigma.Enigma(rotor.ROTOR_Reflector_A, rotor.ROTOR_I, rotor.ROTOR_II, rotor.ROTOR_III, key="ABC")
+    >>> engr = enigma.Enigma(rotor.ROTOR_Reflector_A, rotor.ROTOR_I, rotor.ROTOR_II, rotor.ROTOR_III, key="ABC", plugs="AV BS CG DL FU HZ IN KM OW RX")
     >>> print(engr)
 
         Reflector: 
         Model: None
         Date: None
         Wiring: EJMZALYXVBWFCRQUONTSPIKHGD
+
         Rotor 1: 
-        Name: III
-        Model: Enigma 1
-        Date: 1930
+        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("Hello World!")
-    >>> print(res)
-    Rkmwn Irzdg!
-
+    >>> res = engr.encipher("Hello World")
+    >>> print res
+    Imweq Ltzda
 
 Command line:
 
-    $ echo "Hello World" | ./cypher_enigma_safe.py ABC B  I II IV "AV BS CG DL FU HZ IN KM OW RX"
-    Uvbyt Ugaoa
+    $ echo "Hello World" | ./cypher_enigma_safe.py ABC A  I II III "AV BS CG DL FU HZ IN KM OW RX"
+    Imweq Ltzda
 
-    $ echo "Uvbyt Ugaoa" | ./cypher_enigma_safe.py ABC B  I II IV "AV BS CG DL FU HZ IN KM OW RX"
-    Hello World
+    $ echo "Uvbyt Ugaoa" | ./cypher_enigma_safe.py ABC A  I II III "AV BS CG DL FU HZ IN KM OW RX"
+    Imweq Ltzda
 
 License
 -------

pyenigma/cypher_enigma_safe.py

         exit()
     raw = sys.stdin.read(-1)
 
-    plugboard_settings= [(elem[0], elem[1]) for elem in plugs.split(" ")]
-
     rotors = { \
           "I":ROTOR_I,"II":ROTOR_II,"III":ROTOR_III,"IV":ROTOR_IV, \
           "V":ROTOR_V,"VI":ROTOR_VI,"VII":ROTOR_VII \
           "C":ROTOR_Reflector_C \
           }
 
-    engr = Enigma(reflectors[ref], rotors[r1], rotors[r2], rotors[r3], key=key, plugboard_settings=plugboard_settings)
+    engr = Enigma(reflectors[ref], rotors[r1], rotors[r2], rotors[r3], key=key, plugs=plugs)
     res = engr.encipher(raw)
     print(res)

pyenigma/enigma.py

     """
     Represents an Enigma machine.
     """
-    def __init__(self, ref, r3, r2, r1, key="AAA", plugboard_settings="", ringset=1):
+    def __init__(self, ref, r3, r2, r1, key="AAA", plugs="", ringset=1):
         """
         Initialization of the Enigma machine.
         """
         self.reflector.state = 'A'
         self.ringset = ringset
 
+        plugboard_settings= [(elem[0], elem[1]) for elem in plugs.split(" ")]
+
         alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         alpha_out = [" "] * 26
         for i in range(len(alpha)):
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.