Skip to content

Commit 14848b2

Browse files
added configuration for pre-commit.
1 parent 665e260 commit 14848b2

9 files changed

+1050
-129
lines changed

.pre-commit-config.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v2.31.1
4+
hooks:
5+
- id: pyupgrade
6+
args: ["--py37-plus"]
7+
- repo: https://github.com/asottile/reorder_python_imports
8+
rev: v3.0.1
9+
hooks:
10+
- id: reorder-python-imports
11+
additional_dependencies: ["setuptools>60.9"]
12+
- repo: https://github.com/psf/black
13+
rev: 22.3.0
14+
hooks:
15+
- id: black
16+
- repo: https://github.com/PyCQA/flake8
17+
rev: 4.0.1
18+
hooks:
19+
- id: flake8
20+
additional_dependencies:
21+
- flake8-bugbear
22+
- flake8-implicit-str-concat
23+
args: ["--max-line-length=100"]
24+
- repo: https://github.com/pre-commit/pre-commit-hooks
25+
rev: v4.1.0
26+
hooks:
27+
- id: fix-byte-order-marker
28+
- id: trailing-whitespace
29+
- id: end-of-file-fixer
30+
- repo: https://github.com/trailofbits/pip-audit
31+
rev: v2.4.8
32+
hooks:
33+
- id: pip-audit

COPYING

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
671671
may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674-
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
674+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

bin/enigma.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
42
import sys
53

6-
from pyenigma.rotor import *
74
from pyenigma.enigma import *
5+
from pyenigma.rotor import *
86

97
"""A trivial and minimaliste CLI.
108
"""
@@ -29,7 +27,7 @@ def main():
2927
r2 = sys.argv[4].upper()
3028
r3 = sys.argv[5].upper()
3129
plugs = sys.argv[6].upper()
32-
verbose = (sys.argv[7] if 7 < len(sys.argv) else '') in ['-v', '--verbose']
30+
verbose = (sys.argv[7] if 7 < len(sys.argv) else "") in ["-v", "--verbose"]
3331
except:
3432
usage()
3533
exit()
@@ -75,5 +73,6 @@ def main():
7573
r2,
7674
r3,
7775
plugs,
78-
), file=sys.stderr
76+
),
77+
file=sys.stderr,
7978
)

poetry.lock

+735-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyenigma/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#! /usr/bin/env python
2-
#-*- coding: utf-8 -*-
3-
4-
from . import rotor
52
from . import enigma
3+
from . import rotor
64

75
__author__ = "Christophe Goessen, Cedric Bonhomme"
86
__version__ = "0.4.0"

pyenigma/enigma.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#!/usr/bin/env python
2-
#-*- coding: utf-8 -*-
3-
42
from pyenigma.rotor import *
53

6-
class Enigma(object):
4+
5+
class Enigma:
76
"""Represents an Enigma machine.
87
Initializes an Enigma machine with these arguments:
98
- ref: reflector;
109
- r1, r2, r3: rotors;
1110
- key: initial state of rotors;
1211
- plus: plugboard settings.
1312
"""
13+
1414
def __init__(self, ref, r1, r2, r3, key="AAA", plugs="", ring="AAA"):
15-
"""Initialization of the Enigma machine.
16-
"""
15+
"""Initialization of the Enigma machine."""
1716
self.reflector = ref
1817
self.rotor1 = r1
1918
self.rotor2 = r2
@@ -25,29 +24,29 @@ def __init__(self, ref, r1, r2, r3, key="AAA", plugs="", ring="AAA"):
2524
self.rotor1.ring = ring[0]
2625
self.rotor2.ring = ring[1]
2726
self.rotor3.ring = ring[2]
28-
self.reflector.state = 'A'
27+
self.reflector.state = "A"
2928

30-
plugboard_settings= [(elem[0], elem[1]) for elem in plugs.split()]
29+
plugboard_settings = [(elem[0], elem[1]) for elem in plugs.split()]
3130

3231
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3332
alpha_out = [" "] * 26
3433
for i in range(len(alpha)):
3534
alpha_out[i] = alpha[i]
3635
for k, v in plugboard_settings:
37-
alpha_out[ord(k)-ord('A')] = v
38-
alpha_out[ord(v)-ord('A')] = k
36+
alpha_out[ord(k) - ord("A")] = v
37+
alpha_out[ord(v) - ord("A")] = k
3938

4039
try:
4140
self.transtab = str.maketrans(alpha, "".join(alpha_out))
4241
except:
4342
# Python 2
4443
from string import maketrans
45-
self.transtab = maketrans(alpha,"".join(alpha_out))
44+
45+
self.transtab = maketrans(alpha, "".join(alpha_out))
4646

4747
def encipher(self, plaintext_in):
48-
"""Encrypt 'plaintext_in'.
49-
"""
50-
ciphertext = ''
48+
"""Encrypt 'plaintext_in'."""
49+
ciphertext = ""
5150
plaintext_in_upper = plaintext_in.upper()
5251
plaintext = plaintext_in_upper.translate(self.transtab)
5352
for c in plaintext:
@@ -85,13 +84,14 @@ def encipher(self, plaintext_in):
8584
return fres
8685

8786
def __str__(self):
88-
"""Pretty display.
89-
"""
87+
"""Pretty display."""
9088
return """
91-
Reflector: %s
89+
Reflector: {}
9290
93-
Rotor 1: %s
91+
Rotor 1: {}
9492
95-
Rotor 2: %s
93+
Rotor 2: {}
9694
97-
Rotor 3: %s""" % (self.reflector, self.rotor1, self.rotor2, self.rotor3)
95+
Rotor 3: {}""".format(
96+
self.reflector, self.rotor1, self.rotor2, self.rotor3
97+
)

0 commit comments

Comments
 (0)