# bryan-13-ty/introduction-to-cryptography architecture

> Architecture diagram of the GitHub repository bryan-13-ty/introduction-to-cryptography, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bryan-13-ty/introduction-to-cryptography
- Repository: https://github.com/bryan-13-ty/introduction-to-cryptography

## Overview

1. This repository is a teaching-oriented cryptography codebase, not a single application. It collects several independent lab exercises from an “Introduction to Cryptography” course, with each exercise implemented as its own package or standalone program.

2. The top-level architecture is split into two main tracks:
   - Python packages for classical cipher algorithms and shared helpers.
   - C programs for lower-level bit manipulation and block-cipher building blocks.

3. `main.py` is the likely entrypoint for the Python side. It probably acts as a simple driver or demo harness that invokes one or more cipher modules, rather than coordinating a large multi-service workflow.

4. The Python cipher modules are separated by algorithm, each as an importable package:
   - `shift_cipher` for Caesar/shift substitution.
   - `affin_cipher` for affine substitution.
   - `hill_cipher` for matrix-based polygraphic encryption.
   - `permutation_cipher` for transposition/permutation logic.
   - `block_cipher` for block-oriented cipher operations.
   This structure suggests each algorithm can be studied and run independently.

5. `block_cipher` is the most infrastructure-like Python package. It contains `block_cipher.py` plus `tests.py`, so it appears to define reusable block-processing logic and validate it with unit tests. This is the clearest place where algorithmic code and verification are explicitly separated.

6. Shared Python support lives in small utility packages:
   - `constants` likely centralizes alphabet values, numeric parameters, or fixed tables used across ciphers.
   - `utils` contains general helper functions.
   - `decorators` suggests reusable wrappers for cross-cutting behavior such as normalization, validation, or tracing.
   - `fg` appears to be another support module, likely for math/algebra helpers used by some ciphers.
   These form the common foundation used by the cipher packages.

7. The C side focuses on low-level cryptographic primitives and bitwise transformations:
   - `bit_permutation.c` and `bit_permutation_2.c` implement bit permutation exercises.
   - `s-box.c` implements substitution-box logic.
   - `tiny_block_cipher.c` combines those primitives into a small block-cipher-style program.
   These are standalone programs rather than Python extensions, so they form a separate execution boundary.

8. The data flow across the repo is simple and local: plaintext/ciphertext input goes into a specific algorithm module, which applies transformations using shared constants and helper functions, then emits transformed text or blocks. There is no indication of network communication, databases, or external service integration.

9. The repository is organized by lab module, and the `docs/` PDFs under each folder are likely the assignment handouts or specifications for each exercise. They are documentation artifacts, not runtime dependencies, but they explain why the code is split into many small subsystems.

10. From an architecture-diagram perspective, the main boundaries are:
   - Python vs. C implementation tracks.
   - Per-cipher isolation, with minimal coupling between algorithms.
   - Shared helper layer underneath the Python ciphers.
   - Testing attached specifically to the Python block-cipher module.
   The overall system is best drawn as a collection of independent educational cipher implementations sharing a few common utility packages.

Main entry points: [`main.py`](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/main.py) (Main), [`block_cipher/block_cipher.py`](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/block_cipher/block_cipher.py) (Block cipher), [`constants/constants.py`](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/constants/constants.py) (Constants), [`shift_cipher/shift_cipher.py`](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/shift_cipher/shift_cipher.py) (Shift cipher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_python_track["Python ciphers"]
  node_main_py["Main<br/>driver<br/>[main.py]"]
  node_shift_cipher["Shift cipher<br/>substitution<br/>[shift_cipher.py]"]
  node_affin_cipher["Affine cipher<br/>substitution<br/>[affin_cipher.py]"]
  node_hill_cipher["Hill cipher<br/>matrix cipher<br/>[hill_cipher.py]"]
  node_permutation_cipher["Permutation cipher<br/>transposition"]
  node_block_cipher["Block cipher<br/>block logic<br/>[block_cipher.py]"]
  node_block_tests["Block tests<br/>validation<br/>[tests.py]"]
end

subgraph group_support_layer["Shared support"]
  node_constants["Constants<br/>shared tables<br/>[constants.py]"]
  node_utils["Utils<br/>helpers<br/>[utils.py]"]
  node_decorators["Decorators<br/>cross-cutting<br/>[decorators.py]"]
  node_fg["FG<br/>math helpers<br/>[fg.py]"]
end

subgraph group_c_track["C primitives"]
  node_bit_perm_1["Bit perm 1<br/>bit permutation<br/>[bit_permutation.c]"]
  node_bit_perm_2["Bit perm 2<br/>bit permutation"]
  node_s_box["S-box<br/>substitution<br/>[s-box.c]"]
  node_tiny_block["Tiny block<br/>block cipher"]
end

node_main_py -->|"runs"| node_shift_cipher
node_main_py -->|"runs"| node_affin_cipher
node_main_py -->|"runs"| node_hill_cipher
node_main_py -->|"runs"| node_permutation_cipher
node_main_py -->|"runs"| node_block_cipher
node_shift_cipher -->|"uses"| node_constants
node_shift_cipher -->|"uses"| node_utils
node_affin_cipher -->|"uses"| node_constants
node_affin_cipher -->|"uses"| node_utils
node_hill_cipher -->|"uses"| node_constants
node_hill_cipher -->|"uses"| node_fg
node_permutation_cipher -->|"uses"| node_utils
node_block_cipher -->|"uses"| node_constants
node_block_cipher -->|"uses"| node_decorators
node_block_tests -->|"verifies"| node_block_cipher
node_tiny_block -->|"combines"| node_bit_perm_1
node_tiny_block -->|"combines"| node_s_box
node_bit_perm_1 -.->|"related"| node_bit_perm_2

click node_main_py "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/main.py"
click node_shift_cipher "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/shift_cipher/shift_cipher.py"
click node_affin_cipher "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/affin_cipher/affin_cipher.py"
click node_hill_cipher "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/hill_cipher/hill_cipher.py"
click node_permutation_cipher "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/permutation_cipher/permutation_cipher.py"
click node_block_cipher "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/block_cipher/block_cipher.py"
click node_block_tests "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/block_cipher/tests.py"
click node_constants "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/constants/constants.py"
click node_utils "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/utils/utils.py"
click node_decorators "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/decorators/decorators.py"
click node_fg "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/fg/fg.py"
click node_bit_perm_1 "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/bit_permutation/bit_permutation.c"
click node_bit_perm_2 "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/bit_permutation/bit_permutation_2.c"
click node_s_box "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/s_box/s-box.c"
click node_tiny_block "https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/tiny_block_cipher/tiny_block_cipher.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main_py,node_shift_cipher,node_affin_cipher,node_hill_cipher,node_permutation_cipher,node_block_cipher,node_block_tests toneBlue
class node_constants,node_utils,node_decorators,node_fg toneAmber
class node_bit_perm_1,node_bit_perm_2,node_s_box,node_tiny_block toneMint
```

## Components

### Python ciphers

Independent Python lab modules for classical cipher exercises and demos.

- [Main](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/main.py): driver · Top-level Python entrypoint that likely runs demos or simple cipher exercises. · `main.py`
- [Shift cipher](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/shift_cipher/shift_cipher.py): substitution · Caesar-style shift cipher package. · `shift_cipher/shift_cipher.py`
- [Affine cipher](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/affin_cipher/affin_cipher.py): substitution · Affine substitution cipher package. · `affin_cipher/affin_cipher.py`
- [Hill cipher](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/hill_cipher/hill_cipher.py): matrix cipher · Matrix-based polygraphic cipher package. · `hill_cipher/hill_cipher.py`
- [Permutation cipher](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/permutation_cipher/permutation_cipher.py): transposition · Permutation/transposition cipher package. · `permutation_cipher/permutation_cipher.py`
- [Block cipher](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/block_cipher/block_cipher.py): block logic · Reusable Python block-cipher implementation. · `block_cipher/block_cipher.py`
- [Block tests](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/block_cipher/tests.py): validation · Tests for the Python block-cipher module. · `block_cipher/tests.py`

### Shared support

Common helpers used across the Python cipher packages.

- [Constants](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/constants/constants.py): shared tables · Shared numeric and alphabet constants for cipher modules. · `constants/constants.py`
- [Utils](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/utils/utils.py): helpers · General-purpose helper functions used by cipher packages. · `utils/utils.py`
- [Decorators](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/decorators/decorators.py): cross-cutting · Reusable wrappers for shared behavior in Python modules. · `decorators/decorators.py`
- [FG](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/fg/fg.py): math helpers · Auxiliary algebra or finite-structure helpers for cipher logic. · `fg/fg.py`

### C primitives

Standalone C exercises for bit-level permutation and block-cipher building blocks.

- [Bit perm 1](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/bit_permutation/bit_permutation.c): bit permutation · Standalone C exercise for bit permutation transformations. · `bit_permutation/bit_permutation.c`
- [Bit perm 2](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/bit_permutation/bit_permutation_2.c): bit permutation · Second standalone C bit-permutation exercise. · `bit_permutation/bit_permutation_2.c`
- [S-box](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/s_box/s-box.c): substitution · Standalone C substitution-box exercise. · `s_box/s-box.c`
- [Tiny block](https://github.com/bryan-13-ty/introduction-to-cryptography/blob/main/tiny_block_cipher/tiny_block_cipher.c): block cipher · Standalone C program combining permutation and substitution into a tiny block cipher. · `tiny_block_cipher/tiny_block_cipher.c`

## Connections

- Main → Shift cipher: runs · Main entrypoint can invoke cipher demos.
- Main → Affine cipher: runs · Main entrypoint can invoke cipher demos.
- Main → Hill cipher: runs · Main entrypoint can invoke cipher demos.
- Main → Permutation cipher: runs · Main entrypoint can invoke cipher demos.
- Main → Block cipher: runs · Main entrypoint can invoke cipher demos.
- Shift cipher → Constants: uses · Relies on shared alphabet and parameters.
- Shift cipher → Utils: uses · Uses common helper routines.
- Affine cipher → Constants: uses · Relies on shared alphabet and parameters.
- Affine cipher → Utils: uses · Uses common helper routines.
- Hill cipher → Constants: uses · Relies on shared alphabet and parameters.
- Hill cipher → FG: uses · Likely uses math/algebra helpers.
- Permutation cipher → Utils: uses · Uses common helper routines.
- Block cipher → Constants: uses · Shares core block parameters and tables.
- Block cipher → Decorators: uses · Applies reusable wrappers around block operations.
- Block tests → Block cipher: verifies · Tests validate the block-cipher implementation.
- Tiny block → Bit perm 1: combines · Builds on bit permutation logic.
- Tiny block → S-box: combines · Builds on substitution-box logic.
- Bit perm 1 → Bit perm 2: related · Second permutation exercise in the same lab area.
