Commits

Cédric Bonhomme  committed b8ab5b4

Reintroduced plugboard settings. Updated Readme.

  • Participants
  • Parent commits 72511ca

Comments (0)

Files changed (3)

 
 Command line:
 
-    $ echo "Hello World" | ./cypher_enigma_safe.py ABC B  I II IV
-    Iajfb Sqguz
+    $ 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 "Iajfb Sqguz" | ./cypher_enigma_safe.py ABC B  I II IV
+    $ echo "Uvbyt Ugaoa" | ./cypher_enigma_safe.py ABC B  I II IV "AV BS CG DL FU HZ IN KM OW RX"
     Hello World
 
 License

File pyenigma/cypher_enigma_safe.py

         r1 = sys.argv[3]
         r2 = sys.argv[4]
         r3 = sys.argv[5]
+        plugs = sys.argv[6]
     except:
         usage()
         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)
+    engr = Enigma(reflectors[ref], rotors[r1], rotors[r2], rotors[r3], key=key, plugboard_settings=plugboard_settings)
     res = engr.encipher(raw)
     print(res)

File pyenigma/enigma.py

     """
     Represents an Enigma machine.
     """
-    def __init__(self, ref, r3, r2, r1, key='AAA', ringset=1):
+    def __init__(self, ref, r3, r2, r1, key="AAA", plugboard_settings="", ringset=1):
         """
         Initialization of the Enigma machine.
         """
         alpha_out = [" "] * 26
         for i in range(len(alpha)):
             alpha_out[i] = alpha[i]
+        for k, v in plugboard_settings:
+            alpha_out[ord(k)-ord('A')] = v
+            alpha_out[ord(v)-ord('A')] = k
 
         try:
             self.transtab = str.maketrans(alpha, "".join(alpha_out))