Skip to content

Athang69/file_encrypter_decrypter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Encrypter / Decrypter

graph TD
	User((user)) -->|file| FileDE[file de/encryptor]
	FileDE -->|open/write/read| IO[IO]
	FileDE -->|submits a process| PM[ProcessManagement]
	PM -->|submits to the queue| Queue[/Queue/]
	PM -->|consume| Queue
	Queue --> Child[spin up a child process]
	Child -->|signal from child| PM
	Child --> EndDecrypt((en/decrypt))
	EndDecrypt --> FileDE
Loading

A small, portable C++ utility for in-place bytewise encryption and decryption of files. It supports two modes:

  • cryption: encrypt/decrypt a single file from a command-line task string.
  • encrypt_decrypt: interactive mode for processing all files under a directory (recursively) using a worker queue.

This repository is intended to be small and explicit; the cipher is a simple byte rotation using a derived 8-bit key. It is NOT suitable for protecting sensitive data in production without additional cryptographic hardening (see Security section).

Status: Buildable on Linux with g++ (C++17).

Quick links:

  • Build: make
  • Single-file helper: cryption
  • Directory runner: encrypt_decrypt

Table of contents

  • Overview
  • Build
  • Usage
  • .env / Key derivation
  • File semantics
  • Security notes
  • Contributing
  • License

Overview

The project processes files in-place. The algorithm reads each byte and either adds or subtracts a single 0–255 key (modulo 256). The key is derived deterministically from the .env file so you can store a passphrase or longer key material; the program derives an 8-bit integer from that material.

Use cryption when you want to operate on a single file from scripts. Use encrypt_decrypt when you want to process an entire directory recursively and leverage the built-in worker queue.

Build

Requirements:

  • Linux (or similar)
  • g++ with C++17 support
  • make

Build the project:

make

This produces two executables in the repo root:

  • cryption - helper for single-file tasks
  • encrypt_decrypt - interactive directory processor

Usage

Single-file mode (recommended for scripts):

./cryption "path/to/file,ENCRYPT"
./cryption "path/to/file,DECRYPT"

Note: the task string format is <file-path>,<ENCRYPT|DECRYPT> (no spaces around the comma).

Interactive directory mode:

./encrypt_decrypt
# When prompted:
# Enter the directory path
#   -> path/to/directory
# Enter the action (encrypt/decrypt)
#   -> ENCRYPT  (or DECRYPT)

The interactive mode will recurse the directory and attempt to open each regular file. Files are modified in-place.

.env / Key derivation

Place a .env file in the project root. The application supports several formats for this file:

  • Hex string (even length): the program parses hex bytes and sums them modulo 256 to derive the key.
  • Decimal integer: parsed as base-10 and reduced modulo 256.
  • Any other text: the program sums the UTF-8 byte values modulo 256.

Example valid .env contents:

3
e95e8414e66790b9b89afc9e6e57a977145e4e794e9494886acca6c7a6a2ffd1

The design intentionally derives an 8-bit key from arbitrarily sized key material so you can keep long secrets in .env. If you need a stronger cipher, integrate a vetted crypto library (e.g., libsodium or OpenSSL) and store keys securely.

File semantics and safety

  • Files are modified in-place; no automatic backups are made by the tool. Create backups before encrypting important data.
  • The operation is symmetric: running the same action twice will not revert (ENCRYPT twice != original). Use DECRYPT to reverse an earlier ENCRYPT when using the same .env key material.

Security notes

  • This project implements a simple byte rotation cipher and is NOT cryptographically secure. Do not use it to protect sensitive data.
  • If you need secure encryption, replace the transformation with a modern authenticated cipher (e.g., XChaCha20-Poly1305) and manage keys using OS-provided secret stores or hardware modules.

Contributing

Contributions are welcome. Keep changes small and focused. If you propose changing the cipher, include tests demonstrating interoperability and backward compatibility.

Suggested workflow:

git checkout -b feat/your-change
make
./cryption "test/file,ENCRYPT"

Run make clean to remove build artifacts.

Testing

Simple manual test:

cp -a test/test1.txt test/test1.txt.bak
./cryption "test/test1.txt,ENCRYPT"
./cryption "test/test1.txt,DECRYPT"
cmp --silent test/test1.txt test/test1.txt.bak && echo "OK"

License

MIT - see LICENSE.


About

A file Encryptor & Decryptor Written in C++

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors