Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b619384a1 | |||
| 12b9884572 | |||
| 83b60b5cc2 | |||
| 2d6546ab83 | |||
| c255185084 |
1
decrypted.bin
Normal file
1
decrypted.bin
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Hello, this is a test file for encryption!
|
||||||
45
otp.c
45
otp.c
@@ -271,7 +271,7 @@ int command_line_mode(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void show_main_menu(void) {
|
void show_main_menu(void) {
|
||||||
printf("=== Main Menu ===\n\n");
|
printf("======================== Main Menu ========================\n");
|
||||||
printf("\033[4mT\033[0mext encrypt\n");
|
printf("\033[4mT\033[0mext encrypt\n");
|
||||||
printf("\033[4mF\033[0mile encrypt\n");
|
printf("\033[4mF\033[0mile encrypt\n");
|
||||||
printf("\033[4mD\033[0mecrypt\n");
|
printf("\033[4mD\033[0mecrypt\n");
|
||||||
@@ -461,16 +461,21 @@ int handle_encrypt_menu(void) {
|
|||||||
|
|
||||||
int ascii_armor = (atoi(format_input) == 2) ? 1 : 0;
|
int ascii_armor = (atoi(format_input) == 2) ? 1 : 0;
|
||||||
|
|
||||||
// Ask for custom output filename (optional)
|
// Generate default output filename and use enhanced input function
|
||||||
printf("\nEnter output filename (or press Enter for default): ");
|
char default_output[1024]; // Increased size to prevent truncation warnings
|
||||||
|
if (ascii_armor) {
|
||||||
|
snprintf(default_output, sizeof(default_output), "%s.otp.asc", input_file);
|
||||||
|
} else {
|
||||||
|
snprintf(default_output, sizeof(default_output), "%s.otp", input_file);
|
||||||
|
}
|
||||||
|
|
||||||
char output_file[512];
|
char output_file[512];
|
||||||
if (!fgets(output_file, sizeof(output_file), stdin)) {
|
if (get_filename_with_default("Output filename:", default_output, output_file, sizeof(output_file)) != 0) {
|
||||||
printf("Error: Failed to read input\n");
|
printf("Error: Failed to read input\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
output_file[strcspn(output_file, "\n")] = 0;
|
|
||||||
|
|
||||||
const char* output_filename = (strlen(output_file) > 0) ? output_file : NULL;
|
const char* output_filename = output_file;
|
||||||
|
|
||||||
return encrypt_file(pad_input, input_file, output_filename, ascii_armor);
|
return encrypt_file(pad_input, input_file, output_filename, ascii_armor);
|
||||||
}
|
}
|
||||||
@@ -517,16 +522,32 @@ int handle_decrypt_menu(void) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask for custom output filename (optional)
|
// Generate smart default output filename and use enhanced input function
|
||||||
printf("\nEnter output filename (or press Enter for default): ");
|
char default_output[512];
|
||||||
|
strncpy(default_output, input_file, sizeof(default_output) - 1);
|
||||||
|
default_output[sizeof(default_output) - 1] = '\0';
|
||||||
|
|
||||||
|
// Remove common encrypted extensions to get a better default
|
||||||
|
if (strstr(default_output, ".otp.asc")) {
|
||||||
|
// Replace .otp.asc with original extension or no extension
|
||||||
|
char* ext_pos = strstr(default_output, ".otp.asc");
|
||||||
|
*ext_pos = '\0';
|
||||||
|
} else if (strstr(default_output, ".otp")) {
|
||||||
|
// Replace .otp with original extension or no extension
|
||||||
|
char* ext_pos = strstr(default_output, ".otp");
|
||||||
|
*ext_pos = '\0';
|
||||||
|
} else {
|
||||||
|
// No recognized encrypted extension, add .decrypted suffix
|
||||||
|
strncat(default_output, ".decrypted", sizeof(default_output) - strlen(default_output) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
char output_file[512];
|
char output_file[512];
|
||||||
if (!fgets(output_file, sizeof(output_file), stdin)) {
|
if (get_filename_with_default("Output filename:", default_output, output_file, sizeof(output_file)) != 0) {
|
||||||
printf("Error: Failed to read input\n");
|
printf("Error: Failed to read input\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
output_file[strcspn(output_file, "\n")] = 0;
|
|
||||||
|
|
||||||
const char* output_filename = (strlen(output_file) > 0) ? output_file : NULL;
|
const char* output_filename = output_file;
|
||||||
|
|
||||||
return decrypt_file(input_file, output_filename);
|
return decrypt_file(input_file, output_filename);
|
||||||
}
|
}
|
||||||
@@ -2447,7 +2468,7 @@ int get_filename_with_default(const char* prompt, const char* default_path, char
|
|||||||
}
|
}
|
||||||
} else if (c >= 32 && c <= 126) {
|
} else if (c >= 32 && c <= 126) {
|
||||||
// Printable character
|
// Printable character
|
||||||
if (buffer_len < sizeof(edit_buffer) - 1) {
|
if (buffer_len < (int)sizeof(edit_buffer) - 1) {
|
||||||
// Move everything after cursor one position right
|
// Move everything after cursor one position right
|
||||||
memmove(&edit_buffer[cursor_pos + 1], &edit_buffer[cursor_pos], buffer_len - cursor_pos + 1);
|
memmove(&edit_buffer[cursor_pos + 1], &edit_buffer[cursor_pos], buffer_len - cursor_pos + 1);
|
||||||
edit_buffer[cursor_pos] = c;
|
edit_buffer[cursor_pos] = c;
|
||||||
|
|||||||
BIN
output.otp
Normal file
BIN
output.otp
Normal file
Binary file not shown.
1
test_decrypt.txt
Normal file
1
test_decrypt.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Test file content for decryption
|
||||||
BIN
test_decrypt.txt.otp
Normal file
BIN
test_decrypt.txt.otp
Normal file
Binary file not shown.
7
test_file.txt.otp.asc
Normal file
7
test_file.txt.otp.asc
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
-----BEGIN OTP MESSAGE-----
|
||||||
|
Version: v0.2.29
|
||||||
|
Pad-ChkSum: d0d4a489354348b08d8c7b324814d8c50010042e9da47f2c973f32a16a09101b
|
||||||
|
Pad-Offset: 57
|
||||||
|
|
||||||
|
05S8GfS0tFfczNMUz0xrieFGoPSREM4uo5QhFGoBCcOzjfTXTDMt3hRtAQ==
|
||||||
|
-----END OTP MESSAGE-----
|
||||||
1
test_input.txt
Normal file
1
test_input.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This is a test file for encryption.
|
||||||
Reference in New Issue
Block a user