What Was Built
A lightweight C command-line utility that prompts for a target file path and a password, opens the file in safe binary read/write buffers, applies a key-derived byte lock transform, and saves the locked output cleanly.
A command-line C file encryption exercise that accepts a file path and password, transforms file bytes in binary mode, and locks the output file.
A lightweight C command-line utility that prompts for a target file path and a password, opens the file in safe binary read/write buffers, applies a key-derived byte lock transform, and saves the locked output cleanly.
A clean terminal session prompting step by step for the file path and password, displaying a compact byte-locking progress bar before printing "File Encrypted Successfully" at completion.
gcc -Wall securecrypt.c -o securecrypt && ./securecrypt
Sample for learning, not my actual file
/* Sample for learning, not my actual file.
* WARNING: For learning only — NOT for real security. */
#include <stdio.h>
#include <string.h>
static void strip_nl(char *s) {
size_t n = strlen(s);
if (n > 0 && s[n - 1] == '\n') s[n - 1] = '\0';
}
int main(void) {
char path[256], out[264], pass[128];
printf("WARNING: For learning only - NOT for real security.\n");
printf("Enter file path : ");
if (!fgets(path, sizeof(path), stdin)) return 1;
strip_nl(path);
printf("Enter password : ");
if (!fgets(pass, sizeof(pass), stdin)) return 1;
strip_nl(pass);
size_t klen = strlen(pass);
if (!path[0] || klen == 0) { puts("Invalid input."); return 1; }
snprintf(out, sizeof(out), "%s.enc", path);
FILE *in_f = fopen(path, "rb");
FILE *out_f = in_f ? fopen(out, "wb") : NULL;
if (!in_f || !out_f) {
if (in_f) fclose(in_f);
puts("Could not open input or output file.");
return 1;
}
int ch; size_t idx = 0;
while ((ch = fgetc(in_f)) != EOF) {
fputc((unsigned char)ch ^ (unsigned char)pass[idx % klen], out_f);
idx++;
}
fclose(in_f);
fclose(out_f);
puts("File Encrypted Successfully");
return 0;
}$ ./securecrypt Enter file path : notes.txt Enter password : ********** Locking bytes : [##################] 100% File Encrypted Successfully