# numillyash/coursework architecture

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

- Interactive diagram: https://gitdiagram.com/numillyash/coursework
- Repository: https://github.com/numillyash/coursework

## Overview

##### Main Components
- Command-Line Interface (CLI): Represented as the entry point where the user invokes the application with various flags (genkey, sign, check, encrypt, and decrypt).
- Core Cryptographic Engine:
- RSA Key Generation Module: Handles the generation of public/private keys, making use of various prime files and key size parameters.
- Signature Module: Computes and verifies digital signatures.
- Encryption/Decryption Module: Provides the logic for encrypting and decrypting files.
- Optimization and Math Modules:
- Algorithm-level Optimizations (e.g., FFT-based multiplication)
- Machine-independent and machine-specific (assembly) optimization routines
- Underlying Mathematical Computations (Karatsuba multiplication and other routines)
- File I/O and Utility Module:
- Reads and writes files (plain text, encrypted data, keys, and signatures)
- Parsing configuration and command-line arguments (likely involving helper routines as seen in files like help.h)
- Testing and Validation Suite:
- Test Scripts and Input Files: Organized under the tests directory and separate input files for validating encryption, decryption, signing, and key generation.
- Build and Configuration:
- Makefile and configuration headers (config.h) that indicate build-time configurations and dependencies.

##### Relationships and Interactions
- User calls the CLI which routes to the appropriate module (key generation, signing, checking, encryption, or decryption).
- The CLI layer passes file paths and parameters to the core engine.
- The Core Engine processes input files using the cryptographic algorithms (with internal callouts to optimized math routines).
- Optimized routines (whether in C or inline assembly) are called as sub-components within the engine for critical operations.
- The File I/O module interacts with the system to load input data (plain text, keys, etc.) and produce output files.
- Testing components validate that the chain of operations (from CLI inputs to cryptographic result and file outputs) works as expected.

##### Architectural Patterns and Design Principles
- Modular Design: Each major functionality (key generation, encryption, decryption, signing, verifying) is encapsulated within its own module. This organizes the code logically and makes it easier to maintain.
- Separation of Concerns: The project separates user interaction (CLI) from the cryptographic engine and from the optimization logic.
- Extensibility: The design anticipates the possibility of integrating or changing optimization routines (e.g., switching between Karatsuba and FFT methods).
- Emphasis on Testing: A dedicated test suite indicates a test-driven approach to ensure each module performs correctly.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: CLI
    CLI("CLI Entry Point/Command Parser"):::cli

    %% Core Cryptographic Engine Subgraph
    subgraph "Core Cryptographic Engine"
        RSA_KeyGen("RSA Key Generation Module"):::core
        Signature_Module("Signature Module"):::core
        EncDec_Module("Encryption/Decryption Module"):::core
    end

    %% Supporting Modules
    Opt("Optimization & Math Modules"):::opt
    FileIO("File I/O & Utility Module"):::io
    TestSuite("Testing and Validation Suite"):::test
    Build("Build & Config"):::build

    %% Arrows from CLI to Core Engine Modules
    CLI -->|"sendsCommands"| RSA_KeyGen
    CLI -->|"sendsCommands"| Signature_Module
    CLI -->|"sendsCommands"| EncDec_Module

    %% Core Engine Modules use Optimized Math routines
    RSA_KeyGen -->|"usesOptimizations"| Opt
    Signature_Module -->|"usesOptimizations"| Opt
    EncDec_Module -->|"usesOptimizations"| Opt

    %% Core Engine Modules interact with File I/O Module
    RSA_KeyGen -->|"fileIO"| FileIO
    Signature_Module -->|"fileIO"| FileIO
    EncDec_Module -->|"fileIO"| FileIO

    %% Testing Suite verifies Core Functionality and File I/O
    TestSuite -->|"tests"| RSA_KeyGen
    TestSuite -->|"tests"| Signature_Module
    TestSuite -->|"tests"| EncDec_Module
    TestSuite -->|"tests"| FileIO

    %% Build and Config feeds into CLI, Core Engine and File I/O
    Build -->|"builds"| CLI
    Build -->|"builds"| RSA_KeyGen
    Build -->|"builds"| FileIO

    %% Click Events
    click CLI "https://github.com/numillyash/coursework/blob/master/Coursework/Coursework.c"
    click RSA_KeyGen "https://github.com/numillyash/coursework/blob/master/Coursework/RSA.c"
    click Signature_Module "https://github.com/numillyash/coursework/blob/master/Coursework/tests/test_sign.sh"
    click EncDec_Module "https://github.com/numillyash/coursework/blob/master/Coursework/tests/test_encrypt.sh"
    click Opt "https://github.com/numillyash/coursework/blob/master/Coursework/bit_LA.c"
    click FileIO "https://github.com/numillyash/coursework/blob/master/Coursework/_file_.c"
    click TestSuite "https://github.com/numillyash/coursework/tree/master/Coursework/tests"
    click Build "https://github.com/numillyash/coursework/tree/master/Coursework/Makefile"

    %% Styles
    classDef cli fill:#9fdfbf,stroke:#333,stroke-width:2px;
    classDef core fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef opt fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef io fill:#ffe082,stroke:#333,stroke-width:2px;
    classDef test fill:#ffcc80,stroke:#333,stroke-width:2px;
    classDef build fill:#f8bbd0,stroke:#333,stroke-width:2px;
```
