https://github.com/cedricbonhomme/pyenigma
Python Enigma cypher machine simulator.
https://github.com/cedricbonhomme/pyenigma
engine enigma enigma-machine enigma-simulator simulator
Last synced: about 1 year ago
JSON representation
Python Enigma cypher machine simulator.
- Host: GitHub
- URL: https://github.com/cedricbonhomme/pyenigma
- Owner: cedricbonhomme
- License: gpl-3.0
- Created: 2017-03-15T09:05:15.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-01-13T19:26:46.000Z (over 1 year ago)
- Last Synced: 2025-03-28T00:49:50.422Z (about 1 year ago)
- Topics: engine, enigma, enigma-machine, enigma-simulator, simulator
- Language: Python
- Homepage: https://github.com/cedricbonhomme/pyEnigma
- Size: 285 KB
- Stars: 70
- Watchers: 5
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
# pyEnigma
[](https://builds.sr.ht/~cedric/pyenigma)
[pyEnigma](https://sr.ht/~cedric/pyenigma) is a Python Enigma cypher machine
simulator.
For reporting issues, visit the tracker here:
https://todo.sr.ht/~cedric/pyenigma
## Usage
### As a Python library
You can install pyEnigma with Poetry.
```bash
$ poetry install pyenigma
```
Then you can use it in your program:
```bash
$ poetry shell
(pyenigma-py3.12) $
(pyenigma-py3.12) $ python
```
```python
Python 3.12.1 (main, Dec 31 2023, 00:21:59) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyenigma import enigma
>>> from pyenigma import rotor
>>> print(rotor.ROTOR_GR_III)
Name: III
Model: German Railway (Rocket)
Date: 7 February 1941
Wiring: JVIUBHTCDYAKEQZPOSGXNRMWFL
>>>
>>> engine = enigma.Enigma(rotor.ROTOR_Reflector_A, rotor.ROTOR_I,
rotor.ROTOR_II, rotor.ROTOR_III, key="ABC",
plugs="AV BS CG DL FU HZ IN KM OW RX")
>>> print(engine)
Reflector:
Name: Reflector A
Model: None
Date: None
Wiring: EJMZALYXVBWFCRQUONTSPIKHGD
Rotor 1:
Name: I
Model: Enigma 1
Date: 1930
Wiring: EKMFLGDQVZNTOWYHXUSPAIBRCJ
State: A
Rotor 2:
Name: II
Model: Enigma 1
Date: 1930
Wiring: AJDKSIRUXBLHWTMCQGZNPYFVOE
State: B
Rotor 3:
Name: III
Model: Enigma 1
Date: 1930
Wiring: BDFHJLCPRTXVZNYEIWGAKMUSQO
State: C
>>> secret = engine.encipher("Hello World")
>>> print(secret)
Qgqop Vyzxp
```
### As a program
Install pyEnigma system wide with pipx:
```bash
$ pipx install pyenigma
```
Then you can use the command line interface:
```bash
$ echo "Hello World" | enigma ABC A I II III "AV BS CG DL FU HZ IN KM OW RX"
Qgqop Vyzxp
$ echo "Qgqop Vyzxp" | enigma ABC A I II III "AV BS CG DL FU HZ IN KM OW RX"
Hello World
```
If you want to display the rotor output state:
```bash
$ echo "Hello World" | enigma ABC A I II III "AV BS CG DL FU HZ IN KM OW RX" --verbose
Qgqop Vyzxp
KBC A I II III "AV BS CG DL FU HZ IN KM OW RX"
```
The state is returned on ```stderr```, so you can still use the Unix pipe mechanism:
```bash
$ echo "Hello World" | enigma ABC A I II III "AV BS CG DL FU HZ IN KM OW RX" --verbose | enigma ABC A I II III "AV BS CG DL FU HZ IN KM OW RX"
KBC A I II III "AV BS CG DL FU HZ IN KM OW RX"
Hello World
```
## License
pyEnigma is licensed under
[GNU General Public License version 3](https://www.gnu.org/licenses/gpl-3.0.html)
## Author
* [Christophe Goessen](https://github.com/cgoessen) (initial author)
* [Cédric Bonhomme](https://www.cedricbonhomme.org)