Files
EnigmaMachine/README.md

68 lines
2.8 KiB
Markdown
Raw Permalink Normal View History

2025-09-04 12:52:37 -04:00
# Enigma Machine
2025-11-02 18:56:31 -05:00
I still sort of remember being a kid and discovering that you could make a map of letters and from that have a simple
encoding mechanism.
For example (in the table shown below), the letter A would be encoded as M, B as N, C as O, and so on.
| Letter | Encoding |
|--------|----------|
| A | M |
| B | N |
| C | O |
| ... | ... |
| Z | L |
This is a [substitution cipher](https://en.wikipedia.org/wiki/Substitution_cipher) and is pretty simplistic by modern standards, but as a kid I thought it was cool [AF](https://www.howtogeek.com/711826/what-does-af-mean/).
One evening I was watching a video on YouTube about the Enigma Machine. It piqued my interest and I decided to make
something in Python to recreate the functionality.
## History
> The Enigma machine is a cipher device developed and used in the early- to mid-20th century to protect commercial,
> diplomatic, and military communication. It was employed extensively by Nazi Germany during World War II, in all
> branches of the German military. The Enigma machine was considered so secure that it was used to encipher the most
> top-secret messages.
>
> The Enigma has an electromechanical rotor mechanism that scrambles the 26 letters of the alphabet. In typical use, one
> person enters text on the Enigma's keyboard and another person writes down which of the 26 lights above the keyboard
> illuminated at each key press. If plaintext is entered, the illuminated letters are the ciphertext. Entering
> ciphertext transforms it back into readable plaintext. The rotor mechanism changes the electrical connections between
> the keys and the lights with each keypress.
>
> -- [Wikipedia](https://en.wikipedia.org/wiki/Enigma_machine)
2025-10-26 11:40:29 -04:00
## Usage
`uv run main.py "[message]" e|d [int]`
Where:
- __"[message]"__ is the message to be encrypted/decrypted. Should be in quotes.
- __e|d__ is the direction of the message (encrypt or decrypt).
- __int__ is the number of iterations to be made.
### Seed Values
When encrypting a message, a file will be written to the current directory. This file contains the seed values used to
generate the encryption/decryption keys.
The seed values are integers between 0 and 58. In the file, each seed value is on a new line.
The number of iterations should match the number of seed values used.
### Examples
#### Encode
Encode the message "You are here." with three iterations.
`uv run main.py "You are here." e 3`
The command above will create a file called "seed_values.txt" with the generated seed values.
#### Decode
Decode the message "NTb!QDbGDQDa" with three iterations.
`uv run main.py '.NTb!QDbGDQDa' d 3`
The command above expects a file called "seed_values.txt" with the seed values used to encode the message from the preceding example.
2025-10-26 11:40:29 -04:00
## TODO
- [ ] Add a param to tell the `encode` function to use an existing seed file.
2025-10-26 11:40:29 -04:00