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.
- 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.
- C++ Compiler: Needs
g++with C++17 support. - Python: Python 3.x for the
makeDirs.pyscript. - OS: Works on Linux/macOS (uses POSIX semaphores and shared memory).
- Libraries: Just standard C++ libraries (like
<filesystem>,<fstream>).
-
Clone the repo:
git clone https://github.com/abhinav-1504/EncryptX-CPP.git cd EncryptX-CPP -
Make sure you have a
.envfile in the root with a single number (like8717) as the key. -
Build the programs (creates
encrypt_decryptandcryption):make
-
Create Test Files (Optional):
Run the Python script to make a
testdirectory with 10 random text files:python3 makeDirs.py
-
Run the Program:
Start the main program:
./encrypt_decrypt
- Enter the directory path (e.g.,
test). - Type
encryptordecryptfor the action.
- Enter the directory path (e.g.,
-
What Happens:
- The program reads the key from
.envand 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.
- The program reads the key from
::
.
├── .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
-
Main Program (
encrypt_decrypt):- Asks for a directory and action (encrypt/decrypt).
- Scans the directory and creates a
Taskfor each file. - Sends tasks to a queue in
ProcessManagement, which forks processes to handle them.
-
Encryption/Decryption (
Cryption.cpp):- Reads the key from
.envviaReadEnvclass. - Shifts file characters forward (encrypt) or backward (decrypt) by the key.
- Uses binary mode for file operations.
- Reads the key from
-
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:
IOclass opens and manages file streams.ReadEnvreads the key from.env.
-
Test Files:
makeDirs.pycreates 10 text files with 1000 random characters each in atestfolder.
- The
.envkey 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
cryptionprogram is used internally for processing tasks from the queue.
Remove compiled files:
make cleanNo license. Feel free to use or modify it.