A command-line tool written in C++17 to encrypt or decrypt all files within a specified directory using a simple Caesar cipher based on an integer key. The key is read from a .env file located in the same directory as the executable. This tool utilizes multiple threads (std::thread) for potentially faster concurrent processing of files.
This program uses a very basic Caesar cipher (byte addition/subtraction). It is NOT cryptographically secure and should NOT be used for protecting sensitive data. It offers minimal obfuscation at best and is easily broken. Its primary purpose is educational or for non-critical, simple obfuscation tasks.
- Recursively scans a specified directory.
- Encrypts or decrypts all regular files found within the directory.
- Uses a simple, reversible byte-wise Caesar cipher.
- Reads the integer encryption/decryption key from a
.envfile. - Utilizes C++ standard threads (
std::thread) to process files concurrently. - Simple interactive command-line interface.
- Includes basic error handling for file access and invalid input.
- C++ Compiler: A compiler supporting C++17 (e.g., GCC 9+ or Clang).
- Make: The
makebuild utility. - (Windows) For compiling on Windows, the MSYS2 environment with the UCRT64 toolchain (
mingw-w64-ucrt-x86_64-toolchain) is recommended, as the providedmakefileis configured for it. Ensuremakeis installed within MSYS2 (pacman -S make).
-
Clone or Download: Get the source code into a local directory.
# Example using git: # git clone <your-repo-url> # cd <repository-directory>
-
Compile using Make: Navigate to the project's root directory (where the
makefileis located) in your terminal or MSYS2 UCRT64 shell and run:make clean && makeThis will compile the source files and create an executable named
file_processor(Linux/macOS) orfile_processor.exe(Windows) in the current directory.- Note for Windows/MSYS2 Users: The
makefileincludes the necessary-lstdc++fsand-pthreadflags required for linking the filesystem and thread libraries with the MinGW g++ compiler provided by MSYS2.
- Note for Windows/MSYS2 Users: The
-
Create
.envFile: Before running the program, create a file named exactly.envin the same directory as thefile_processorexecutable. Inside this file, put only the integer number you want to use as the encryption/decryption key.- Example
.envcontent:12345 - Important: The file should contain only the digits of the key. Any other characters will cause an error.
- Example
-
Run the Executable: Open your terminal or MSYS2 shell, navigate to the directory containing
file_processorand the.envfile, and run it:./file_processor
(On Windows, you might need
./file_processor.exeor justfile_processor.exe). -
Follow Prompts:
- Enter the directory path: Provide the full or relative path to the directory containing the files you want to process.
- Examples:
/home/user/documents/my_files./test_dataC:/Users/YourUser/Desktop/files_to_processC:\Users\YourUser\Documents\Important Stuff(Backslashes often work but forward slashes are usually safer in shells)
- Do NOT include surrounding quotes (
") in the path when prompted, unless you modify the code to handle them specifically.
- Examples:
- Enter the action (encrypt/decrypt): Type
encryptordecryptand press Enter.
- Enter the directory path: Provide the full or relative path to the directory containing the files you want to process.
-
Processing: The program will scan the directory, print the key it's using, and then dispatch tasks to threads to process the files. It will print progress/completion messages.
🚨 CAUTION: The encryption/decryption happens in-place, modifying the original files. Ensure you have backups if the data is important, especially before running
encrypton a directory for the first time. Do NOT runencrypton the project's own source code directory unless you intend to and know how to recover it!
├── .env # User-created: Contains the encryption key (integer) ├── file_processor # Compiled executable (Linux/macOS) ├── file_processor.exe # Compiled executable (Windows) ├── main.cpp # Main application logic, CLI, directory scanning ├── makefile # Build instructions for make ├── README.md # This file └── src # Source code directory └── app ├── encryptDecrypt │ ├── Cryption.cpp │ ├── Cryption.hpp │ └── CryptionMain.cpp # Optional: Standalone utility for testing Cryption.hpp ├── fileHandling │ ├── IO.cpp │ ├── IO.hpp │ ├── ReadEnv.cpp │ └── ReadEnv.hpp └── processes ├── ProcessManagement.cpp ├── ProcessManagement.hpp └── Task.hpp
- Weak Security: As stated, the Caesar cipher is trivial to break.
- In-Place Modification: Files are overwritten directly. Interruption during processing could lead to corrupted files. No recovery mechanism is built-in besides manually decrypting.
- Error Handling: Basic error handling is present, but edge cases might not be fully covered.
- Large Files/Directories: Performance with extremely large files or a huge number of files hasn't been extensively tested and might be limited by memory or thread management overhead.
- Key Management: Reading the key from a plain text
.envfile is not secure practice for real applications.
This project is licensed under the MIT License - see the LICENSE file (you would need to create this file) for details.