Skip to content

Commit

Permalink
Fixed flake8 warnings. Bumped release number. Now requires Python 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Jan 7, 2024
1 parent f805de8 commit 350082f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
28 changes: 14 additions & 14 deletions bin/enigma.py
Original file line number Diff line number Diff line change
@@ -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.
"""
Expand All @@ -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],
Expand Down
6 changes: 2 additions & 4 deletions pyenigma/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 1 addition & 8 deletions pyenigma/enigma.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from pyenigma.rotor import *


class Enigma:
Expand Down Expand Up @@ -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'."""
Expand Down
8 changes: 4 additions & 4 deletions pyenigma/rotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <cedric@cedricbonhomme.org>",
Expand Down

0 comments on commit 350082f

Please sign in to comment.