Enigma
A simple Python-library of the famous enigma machine.
Requirements
To run this code, you need:
Python 3.x
Usage
enigma_sender = EnigmaMachine(
rotor_wirings=[
"BDFHJLCPRTXVZNYEIWGAKMUSQO",
"AJDKSIRUXBLHWTMCQGZNPYFVOE",
"EKMFLGDQVZNTOWYHXUSPAIBRCJ",
],
rotor_offsets=[0, 0, 0],
reflector_wirings='YRUHQSLDPXNGOKMIEBFZCWVJAT'
)
encripted_msg = enigma_sender.encrypt("HELLO")
enigma_receiver = EnigmaMachine(
rotor_wirings=[
"BDFHJLCPRTXVZNYEIWGAKMUSQO",
"AJDKSIRUXBLHWTMCQGZNPYFVOE",
"EKMFLGDQVZNTOWYHXUSPAIBRCJ",
],
rotor_offsets=[0, 0, 0],
reflector_wirings='YRUHQSLDPXNGOKMIEBFZCWVJAT')
decripted_msg = enigma_receiver.encrypt(encripted_msg)
assert decripted_msg == "HELLO"
Configuration
The EnigmaMachine class takes the following parameters:
-
rotor_wirings: A list of strings, each string represents the wiring of a rotor. The first string is the wiring of the rightmost rotor, the second string is the wiring of the middle rotor, and the third string is the wiring of the leftmost rotor. The wiring is a permutation of the 26 letters of the alphabet. -
rotor_offsets: A list of integers, each integer represents the initial position of a rotor. The first integer is the initial position of the rightmost rotor, the second integer is the initial position of the middle rotor, and the third integer is the initial position of the leftmost rotor. The initial position is a number between 0 and 25. -
reflector_wirings: A string representing the wiring of the reflector. The wiring is a permutation of the 26 letters of the alphabet. -
plugboard_wirings: A dictionary representing the connections of the plugboard. The keys are the letters of the alphabet, and the values are the letters that they are connected to. For example, if the value of the key "A" is "Z", it means that the letter "A" is connected to the letter "Z". -
rotor_names: A list of strings, each string represents the name of a rotor. The first string is the name of the rightmost rotor, the second string is the name of the middle rotor, and the third string is the name of the leftmost rotor. The name of a rotor is a string of 26 letters, each letter represents the position of the rotor when the letter "A" is at the top position. -
reflector_name: Name of the reflector.
Predefined Machines
The library comes with a set of predefined machines that you can use. The machines can be seen here
enigma = EnigmaMachine.from_configuration(
rotor_config=ROTOR_CONFIGURATIONS['Commercial Enigma A, B'],
rotor_offsets = [0,0,0],
reflector_config=REFLECTOR_CONFIGURATIONS['A'],
plugboard_wirings = {}
)
Custom Machine
Alternatively, you can build you own custom machine with your own set of components, by using the Rotor, Reflector, and Plugboard classes. The following components are available:
custom_machine = Machine(
[
PlugBoard(wiring={"A":"B"}),
Rotor(wiring="EKMFLGDQVZNTOWYHXUSPAIBRCJ",offset=0),
Reflector(wiring="YRUHQSLDPXNGOKMIEBFZCWVJAT")
]
)
You can watch an example of usage in the following notebook
Contributing
If you would like to contribute to this project, please follow these steps:
- Fork the repository on GitHub.
- Clone the forked repository to your local machine.
- Create a new branch for your feature or bug fix.
- Implement your changes and test them.
- Commit your changes with descriptive commit messages.
- Push the changes to your fork on GitHub.
- Create a pull request to the original repository.
References
The references that help me build this library are:
- https://www.youtube.com/watch?v=ybkkiGtJmkM&t=245s
- https://www.codesandciphers.org.uk/enigma/example1.htm
- https://www.youtube.com/watch?v=Kz6IlDCyOUY
Metadata
Release files for enigmachine 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| enigmachine-1.0.tar.gz | 9.2 kB | Without provenance | Details for enigmachine-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| enigmachine-1.0-py3-none-any.whl | Python 3 | none | any | Details for enigmachine-1.0-py3-none-any.whl |
Total release size: 17.8 kB
Release files / enigmachine-1.0.tar.gz
| Download URL | enigmachine-1.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07c17e2cf7a6fb0a443517e42d1dea3bdadffb68cf28f9409e519078b93e9ef8
|
|
BLAKE2b-256 checksum How to use checksums |
5dac4633cd1efaaf19756d6ff156fe8efc035f8b3b91873766a780d17831081d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.0
|
Release files / enigmachine-1.0-py3-none-any.whl
| Download URL | enigmachine-1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bad71227d661524a6e9df11529057aa7b282a4e6a7c4b4d4e6f3ab121bbf9b8
|
|
BLAKE2b-256 checksum How to use checksums |
fb097ab9f4a45d9006cd26c2202119761a42e906f23aed0f0da39c3827f80705
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.0
|
Security for enigmachine 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.