# shrimp2845-tw/enigma architecture

> Architecture diagram of the GitHub repository shrimp2845-tw/enigma, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shrimp2845-tw/enigma
- Repository: https://github.com/shrimp2845-tw/enigma

## Overview

##### Project type and purpose
- This is a standalone Python-based simulation tool of the WWII Enigma cipher machine.
- Its goal is to emulate the machine’s core components (rotors, plugboard, reflector) so users can encrypt and decrypt messages via code or CLI.

##### File structure
- Top-level files:
- enigma.py – contains the core classes and logic for the Enigma machine (rotors, plugboard, reflector, wiring, stepping mechanism).
- example.py – a sample CLI/usage script that imports enigma.py, loads a configuration or sample text, runs encryption, and prints output.
- README.md – project description.
- data/ directory: holds sample input (e.g., data/sample.txt) for testing the simulator.

##### README for additional insights
- Confirms the simulation of rotors, plugboard, reflector.
- Mentions ability to use custom or random configurations.
- Implies a clear separation between configuration management and encryption engine.

- User Interface (example.py or any CLI wrapper)
- Configuration Manager – loads/saves rotor settings, plugboard pairs, reflector type (could be coded as part of enigma.py)
- Enigma Engine – the EnigmaMachine class that orchestrates encryption/decryption
- Subcomponents of the Engine:
– Plugboard module/class
– Rotor module/class (with one or more rotor instances chained)
– Reflector module/class
- Data Store – sample input file(s) in data/
- Output – console or file output of encrypted text
b. Relationships and data flow
1. User runs example.py → passes plain text and machine configuration to Configuration Manager.
2. Configuration Manager instantiates EnigmaMachine with Plugboard, list of Rotor objects, Reflector.
3. EnigmaMachine processes each character:
– Passes through Plugboard mapping →
– Sequentially through each Rotor forward →
– Through Reflector →
– Back through Rotors in reverse order →
– Through Plugboard again →
– Steps rotors according to turnover logic
4. Encrypted character returns to example.py → displayed or written to file.
c. Architectural patterns and design principles
- Pipeline pattern for signal flow through multiple components.
- Strategy or Factory pattern for loading different rotor wiring or reflector types.
- Single Responsibility: each class (Plugboard, Rotor, Reflector) handles its own mapping logic.
d. Key technologies and libraries
- Python 3.x standard library
- No external dependencies – pure-Python modules.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User Layer"
        Example["example.py"]:::user
        Output["Ciphertext Output"]:::user
    end

    subgraph "Configuration Layer"
        Config["Configuration Manager"]:::config
    end

    subgraph "Engine Layer"
        Engine["Enigma Engine"]:::engine
        subgraph "Core Components"
            Plugboard["Plugboard"]:::core
            Rotors["Rotor Module"]:::core
            Reflector["Reflector"]:::core
        end
    end

    subgraph "Data Layer"
        Data["Sample Input (data/sample.txt)"]:::data
        Doc["README.md"]:::doc
    end

    Data -->|provides sample| Example
    Example -->|loads config| Config
    Config -->|instantiates| Engine
    Engine -->|returns ciphertext| Example
    Example -->|displays| Output

    %% Core pipeline within Engine
    Plugboard -->|forward mapping| Rotors
    Rotors -->|forward signal| Reflector
    Reflector -->|reverse signal| Rotors
    Rotors -->|reverse mapping| Plugboard

    click Example "https://github.com/shrimp2845-tw/enigma/blob/main/example.py"
    click Config "https://github.com/shrimp2845-tw/enigma/blob/main/enigma.py"
    click Engine "https://github.com/shrimp2845-tw/enigma/blob/main/enigma.py"
    click Plugboard "https://github.com/shrimp2845-tw/enigma/blob/main/enigma.py"
    click Rotors "https://github.com/shrimp2845-tw/enigma/blob/main/enigma.py"
    click Reflector "https://github.com/shrimp2845-tw/enigma/blob/main/enigma.py"
    click Data "https://github.com/shrimp2845-tw/enigma/blob/main/data/sample.txt"
    click Doc "https://github.com/shrimp2845-tw/enigma/blob/main/README.md"

    classDef user fill:#f9f,stroke:#333,stroke-width:1px
    classDef config fill:#ccf,stroke:#333,stroke-width:1px
    classDef engine fill:#cfc,stroke:#333,stroke-width:1px
    classDef core fill:#afa,stroke:#333,stroke-width:1px
    classDef data fill:#ffc,stroke:#333,stroke-width:1px
    classDef doc fill:#fcc,stroke:#333,stroke-width:1px
```
