diff --git a/bin/enigma.py b/bin/enigma.py index 396ef13..17fa381 100755 --- a/bin/enigma.py +++ b/bin/enigma.py @@ -1,8 +1,8 @@ #!/usr/bin/env python import sys -from pyenigma.enigma import * -from pyenigma.rotor import * +from pyenigma import enigma +from pyenigma import rotor """A trivial and minimaliste CLI. """ @@ -28,30 +28,30 @@ def main(): r3 = sys.argv[5].upper() plugs = sys.argv[6].upper() verbose = (sys.argv[7] if 7 < len(sys.argv) else "") in ["-v", "--verbose"] - except: + except Exception: usage() exit() raw = sys.stdin.read(-1) rotors = { - "I": ROTOR_I, - "II": ROTOR_II, - "III": ROTOR_III, - "IV": ROTOR_IV, - "V": ROTOR_V, - "VI": ROTOR_VI, - "VII": ROTOR_VII, + "I": rotor.ROTOR_I, + "II": rotor.ROTOR_II, + "III": rotor.ROTOR_III, + "IV": rotor.ROTOR_IV, + "V": rotor.ROTOR_V, + "VI": rotor.ROTOR_VI, + "VII": rotor.ROTOR_VII, } reflectors = { - "A": ROTOR_Reflector_A, - "B": ROTOR_Reflector_B, - "C": ROTOR_Reflector_C, + "A": rotor.ROTOR_Reflector_A, + "B": rotor.ROTOR_Reflector_B, + "C": rotor.ROTOR_Reflector_C, } if len(key) == 3: # add the default ringstellung key += "-AAA" - engr = Enigma( + engr = enigma.Enigma( reflectors[ref], rotors[r1], rotors[r2], diff --git a/pyenigma/__init__.py b/pyenigma/__init__.py index 45b8d74..2cd7435 100755 --- a/pyenigma/__init__.py +++ b/pyenigma/__init__.py @@ -1,10 +1,8 @@ #! /usr/bin/env python -from . import enigma -from . import rotor __author__ = "Christophe Goessen, Cedric Bonhomme" -__version__ = "0.4.0" +__version__ = "0.5.0" __date__ = "$Date: 2010/01/29 $" -__revision__ = "$Date: 2020/05/17 $" +__revision__ = "$Date: 2024/01/07 $" __copyright__ = "Copyright (c) Christophe Goessen, Cedric Bonhomme" __license__ = "GPLv3" diff --git a/pyenigma/enigma.py b/pyenigma/enigma.py index 99ef378..f5f5af7 100755 --- a/pyenigma/enigma.py +++ b/pyenigma/enigma.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -from pyenigma.rotor import * class Enigma: @@ -36,13 +35,7 @@ def __init__(self, ref, r1, r2, r3, key="AAA", plugs="", ring="AAA"): alpha_out[ord(k) - ord("A")] = v alpha_out[ord(v) - ord("A")] = k - try: - self.transtab = str.maketrans(alpha, "".join(alpha_out)) - except: - # Python 2 - from string import maketrans - - self.transtab = maketrans(alpha, "".join(alpha_out)) + self.transtab = str.maketrans(alpha, "".join(alpha_out)) def encipher(self, plaintext_in): """Encrypt 'plaintext_in'.""" diff --git a/pyenigma/rotor.py b/pyenigma/rotor.py index e1ea5ca..75807df 100755 --- a/pyenigma/rotor.py +++ b/pyenigma/rotor.py @@ -5,7 +5,7 @@ class Reflector: """Represents a reflector.""" def __init__(self, wiring=None, name=None, model=None, date=None): - if wiring != None: + if wiring is not None: self.wiring = wiring else: self.wiring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -58,14 +58,14 @@ def __init__( """ Initialization of the rotor. """ - if wiring != None: + if wiring is not None: self.wiring = wiring else: self.wiring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" self.rwiring = ["0"] * 26 for i in range(0, len(self.wiring)): self.rwiring[ord(self.wiring[i]) - ord("A")] = chr(ord("A") + i) - if notchs != None: + if notchs is not None: self.notchs = notchs else: self.notchs = "" @@ -107,7 +107,7 @@ def encipher_left(self, key): def notch(self, offset=1): self.state = chr((ord(self.state) + offset - ord("A")) % 26 + ord("A")) - notchnext = self.state in self.notchs + # notchnext = self.state in self.notchs # return notchnext def is_in_turnover_pos(self): diff --git a/pyproject.toml b/pyproject.toml index 9a56321..f81d368 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyenigma" -version = "0.4.1" +version = "0.4.5" description = "Python Enigma cypher machine simulator." authors = [ "Cédric Bonhomme ",