Skip to content

abhinav-1504/EncryptX-CPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Encrypt/Decrypt Program

This is a C++ program that encrypts or decrypts all files in a given directory using a Caesar cipher. The key for encryption/decryption comes from a .env file. It uses shared memory and semaphores to process files in parallel with forked processes. There's also a Python script to create test files for trying it out.

What It Does

  • Encrypts or decrypts files in a directory using a key from .env.
  • Uses a simple Caesar cipher (shifts characters by the key value).
  • Processes files concurrently with shared memory and semaphores.
  • Includes a Python script (makeDirs.py) to generate random test files.

Requirements

  • C++ Compiler: Needs g++ with C++17 support.
  • Python: Python 3.x for the makeDirs.py script.
  • OS: Works on Linux/macOS (uses POSIX semaphores and shared memory).
  • Libraries: Just standard C++ libraries (like <filesystem>, <fstream>).

Setup

  1. Clone the repo:

    git clone https://github.com/abhinav-1504/EncryptX-CPP.git
    cd EncryptX-CPP
    
  2. Make sure you have a .env file in the root with a single number (like 8717) as the key.

  3. Build the programs (creates encrypt_decrypt and cryption):

    make
    

How to Use

  1. Create Test Files (Optional):

    Run the Python script to make a test directory with 10 random text files:

    python3 makeDirs.py
    
  2. Run the Program:

    Start the main program:

    ./encrypt_decrypt
    • Enter the directory path (e.g., test).
    • Type encrypt or decrypt for the action.
  3. What Happens:

    • The program reads the key from .env and applies the Caesar cipher to each file.
    • It logs start and end times for each file's processing.
    • If a file or directory can't be opened, it shows an error.

File Structure

::

.
├── .env                    # Holds the encryption key (e.g., 8717)
├── Makefile                # Compiles the C++ programs
├── makeDirs.py             # Python script for test files
├── main.cpp                # Main program for user input and file processing
├── src/
│   ├── app/
│   │   ├── encryptDecrypt/
│   │   │   ├── Cryption.cpp    # Core encryption/decryption code
│   │   │   ├── Cryption.hpp    # Header for encryption functions
│   │   │   ├── CryptionMain.cpp # Standalone encryption program
│   │   ├── fileHandling/
│   │   │   ├── IO.cpp          # Handles file streams
│   │   │   ├── IO.hpp          # Header for file I/O
│   │   │   ├── ReadEnv.cpp     # Reads the .env key
│   │   ├── processes/
│   │   │   ├── ProcessManagement.cpp # Manages task queue and forks
│   │   │   ├── ProcessManagement.hpp # Header for process management
│   │   │   ├── Task.hpp        # Defines tasks for encrypt/decrypt

How It Works

  • Main Program (encrypt_decrypt):

    • Asks for a directory and action (encrypt/decrypt).
    • Scans the directory and creates a Task for each file.
    • Sends tasks to a queue in ProcessManagement, which forks processes to handle them.
  • Encryption/Decryption (Cryption.cpp):

    • Reads the key from .env via ReadEnv class.
    • Shifts file characters forward (encrypt) or backward (decrypt) by the key.
    • Uses binary mode for file operations.
  • Process Management:

    • Uses shared memory to store up to 1000 tasks.
    • Semaphores (itemsSemaphore, emptySlotsSemaphore) ensure safe queue access.
    • Forks a process per task to run executeCryption.
  • File Handling:

    • IO class opens and manages file streams.
    • ReadEnv reads the key from .env.
  • Test Files:

    • makeDirs.py creates 10 text files with 1000 random characters each in a test folder.

Notes

  • The .env key must be a number, or the program might crash.
  • Files must be readable/writable in binary mode.
  • Needs POSIX support (shm_open, sem_open) for shared memory and semaphores.
  • The cryption program is used internally for processing tasks from the queue.

Cleanup

Remove compiled files:

make clean

License

No license. Feel free to use or modify it.

About

High-performance C++ file encryption/decryption system using shared memory, semaphores, and concurrent process execution.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors