# anchii33/ncrypt architecture

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

- Interactive diagram: https://gitdiagram.com/anchii33/ncrypt
- Repository: https://github.com/anchii33/ncrypt

## Overview

##### Project Type and Purpose
- NCrypt is a standalone file encryption tool built in Python. It implements two main utilities – Encryptor and Decryptor – using a GUI from Tkinter. The purpose is to securely encrypt text files using cascaded ciphering, remove the original content, store the final encrypted data in MongoDB, and allow decryption only when all keys are provided in reverse order.

##### Analyzing the File Structure
- Entry Point Files:
- mainEncrypt.py – Initiates the encryption process via the Encryptor UI.
- mainDecrypt.py – Initiates the decryption process via the Decryptor UI.
- Library / Auxiliary Modules:
- cipherFunc.py & ncryptLib.py – Likely hold the core encryption/decryption algorithms and supporting helper functions.
- listReader.py – Possibly used to handle key or file list inputs.
- Supporting Files:
- cipher.txt – May store cipher text or is used as an example input.
- logbook.txt – Presumably used for logging activities or errors.
- README.md – Provides overall project instructions.

##### Key Components
a. User Interface Components (Tkinter UI):
- Encryptor Interface (from mainEncrypt.py)
- Decryptor Interface (from mainDecrypt.py)

b. Core Processing Modules:
- Encryption Module: Uses functionalities from cipherFunc.py and ncryptLib.py to cascade cipher operations.
- Decryption Module: Reverses the encryption process using similar underlying libraries.
- Key Management and Verification: Handles generation, display, and input verification of keys (including reverse ordered verification).

c. Data Handling:
- File Handling: Reading and writing text files, including removal of original content.
- Log Management: Logging events in logbook.txt.
- Database Interaction: Storage and retrieval of the final encrypted data from MongoDB.

##### Architectural Relationships and Interactions
- The Encryptor flow:
- User selects text file(s) and sets the number of encryption iterations.
- The encryption module performs cascaded encryption.
- The original file content is deleted, and a placeholder message (“THIS FILE IS ENCRYPTED”) is written locally.
- The encrypted data (final output) is stored in MongoDB.
- The generated keys (and final key) are displayed in the UI.
- The Decryptor flow:
- User selects the encrypted file and supplies the number of layers plus the final key.
- If the initial verification succeeds, the system prompts for the remaining keys in reverse order.
- On successful key validation, the decryption module rebuilds the original file content.
- The process either confirms success (“SUCCESSFULLY DECRYPTED!”) or fails with an error message.
- Shared libraries (cipherFunc.py, ncryptLib.py) are used by both workflows to perform the core cryptographic transformations.
- listReader.py could serve as a helper module for reading input lists or validating keys.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        EUI("Encryptor UI"):::ui
        DUI("Decryptor UI"):::ui
    end

    %% Processing Layer
    subgraph "Processing Layer"
        ED("Encryption/Decryption Engine"):::engine
        KM("Key Management & Verification"):::helper
    end

    %% External Dependencies
    subgraph "External Dependencies"
        DB("MongoDB"):::database
        FH("File I/O & Logging"):::storage
    end

    %% Encryptor Flow
    EUI -->|"StartEncryption"| ED
    ED -->|"CascadeCipher"| FH
    ED -->|"StoreEncryptedData"| DB
    ED -->|"UseKeyHelper"| KM

    %% Decryptor Flow
    DUI -->|"StartDecryption"| ED
    ED -->|"RetrieveData"| DB
    ED -->|"ValidateKeys"| KM
    ED -->|"RebuildOriginal"| FH

    %% Styles
    classDef ui fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef engine fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef helper fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef database fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef storage fill:#ffccff,stroke:#333,stroke-width:2px;

    %% Click Events
    click EUI "https://github.com/anchii33/ncrypt/blob/main/mainEncrypt.py"
    click DUI "https://github.com/anchii33/ncrypt/blob/main/mainDecrypt.py"
    click ED "https://github.com/anchii33/ncrypt/blob/main/cipherFunc.py"
    click ED "https://github.com/anchii33/ncrypt/blob/main/ncryptLib.py"
    click KM "https://github.com/anchii33/ncrypt/blob/main/listReader.py"
    click FH "https://github.com/anchii33/ncrypt/blob/main/cipher.txt"
    click FH "https://github.com/anchii33/ncrypt/blob/main/logbook.txt"
```
