How bryan-13-ty/introduction-to-cryptography works
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 Main · block_cipher.py Block cipher · constants.py Constants · shift_cipher.py Shift cipher
Components 15
Python ciphers
Independent Python lab modules for classical cipher exercises and demos.
- Main · Top-level Python entrypoint that likely runs demos or simple cipher exercises.
main.py - Shift cipher · Caesar-style shift cipher package.
shift_cipher/shift_cipher.py - Affine cipher · Affine substitution cipher package.
affin_cipher/affin_cipher.py - Hill cipher · Matrix-based polygraphic cipher package.
hill_cipher/hill_cipher.py - Permutation cipher · Permutation/transposition cipher package.
permutation_cipher/permutation_cipher.py - Block cipher · Reusable Python block-cipher implementation.
block_cipher/block_cipher.py - Block tests · Tests for the Python block-cipher module.
block_cipher/tests.py
Shared support
Common helpers used across the Python cipher packages.
- Constants · Shared numeric and alphabet constants for cipher modules.
constants/constants.py - Utils · General-purpose helper functions used by cipher packages.
utils/utils.py - Decorators · Reusable wrappers for shared behavior in Python modules.
decorators/decorators.py - FG · 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 · Standalone C exercise for bit permutation transformations.
bit_permutation/bit_permutation.c - Bit perm 2 · Second standalone C bit-permutation exercise.
bit_permutation/bit_permutation_2.c - S-box · Standalone C substitution-box exercise.
s_box/s-box.c - Tiny block · Standalone C program combining permutation and substitution into a tiny block cipher.
tiny_block_cipher/tiny_block_cipher.c
Connections 18
- 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.