Commits

Cédric Bonhomme committed db8016b

Updated encipher.

Comments (0)

Files changed (2)

pyenigma/cypher_enigma_safe.py

         usage()
         exit()
     raw = sys.stdin.read(-1)
-    seq = raw.upper()
 
     ct = 0
     a = None
 
     engr = Enigma(reflectors[ref], rotors[r1], rotors[r2], \
             rotors[r3], key, plugs)
-    res = engr.encipher(seq)
-    fres = ""
-    for idx, char in enumerate(res):
-        if raw[idx].islower():
-            fres += char.lower()
-        else:
-            fres += char
-    print(fres)
+    res = engr.encipher(raw)
+    print(res)

pyenigma/enigma.py

 
     def encipher(self, plaintext_in):
         ciphertext = ''
-        plaintext = plaintext_in.translate(self.transtab)
+        plaintext_in_upper = plaintext_in.upper()
+        plaintext = plaintext_in_upper.translate(self.transtab)
         for c in plaintext:
             if self.rotor2.is_in_turnover_pos():
                 self.rotor2.notch()
             t = self.rotor2.encipher_left(t)
             t = self.rotor1.encipher_left(t)
             ciphertext += t
-        return ciphertext.translate(self.transtab)
+
+        res = ciphertext.translate(self.transtab)
+
+        fres = ""
+        for idx, char in enumerate(res):
+            if plaintext_in[idx].islower():
+                fres += char.lower()
+            else:
+                fres += char
+        return fres
 
     def __str__(self):
         """