This project implements a One-Time-Pad (OTP) encryption algorithm in x86-64 Assembly for Linux. It uses the Vernam cipher, where the key is as long as the file to encrypt and is used only once. When used correctly, this provides unbreakable encryption.
- Key Generation: Generates a secure key using
/dev/urandom. - Encryption: Encrypts a file using the generated or provided key.
- Decryption: The same key can be used to decrypt a file.
- Key Management: Choose between a generated key or an existing key file.
- File Deletion: Optionally deletes the original file after successful encryption.
- Configurable Block Size: Allows processing large files in blocks.
- OS: Linux
- Architecture: x86-64 (64-bit)
- Assembler: NASM (Netwide Assembler)
- Linker: GNU
ld
nasm -f elf64 otp.asm -o otp.o # Assemble
ld otp.o -o otp # LinkUsage: ./otp [OPTIONS] <input_file> <output_file>
Options:
-g Generate a new key (size = input file)
-k <keyfile> Use an existing key file
-o <keyfile> Save generated key to this file (default: otp_key.bin)
-b <blocksize> Set block size in KiB (default: 64 KiB)
-d Delete original file after encryption
-h, --help Show this help message
- Generate a new key and encrypt a file:
./otp -g -o mykey.bin -d input.txt encrypted.enc- Use an existing key to decrypt a file:
./otp -k mykey.bin encrypted.enc decrypted.txt- Use a custom block size (128 KiB):
./otp -g -o otp_key.bin -b 128 -d input.txt encrypted.enc- Key Generation: With
-g, the program generates a key with random bytes from/dev/urandom. The key size matches the input file size. - Encryption/Decryption: The file is read in blocks (default 64 KiB) and XORed with the key to produce the output.
- Optional File Deletion: If
-dis used and encryption is performed, the original file is deleted after successful encryption.
- Invalid arguments produce an error message.
- File access errors (e.g., missing files or permission issues) produce detailed error messages.
- Insufficient key length or write errors are also reported.
- Invalid arguments: Arguments are missing or incorrect.
- stat() failed: Could not get input file size.
- Cannot open /dev/urandom: Failed to access the random source.
- Key file error: Failed to read/write the key file.
- Key shorter than input: The key is shorter than the input file.
- Write failed: Writing the output file failed.
- File I/O error: General file I/O failure.
- Security: Keep your keys secure. If a key is lost or compromised, the encrypted file is no longer secure.
- Key Size: The key must be at least as large as the file to encrypt.
- One-Time Use: Never reuse an OTP key. Generate a new key for each file.
This project is licensed under the GNU General Public License v3.0 (GPL-3.0).
You may use, modify, and redistribute the code under the GPL-3.0 terms. See the LICENSE file for details.