Compare commits

...

3 Commits

6 changed files with 32 additions and 25 deletions

BIN
files/out2.otp Normal file

Binary file not shown.

Binary file not shown.

55
otp.c
View File

@@ -117,7 +117,7 @@ int main(int argc, char* argv[]) {
} }
int interactive_mode(void) { int interactive_mode(void) {
printf("\n\n\n\n=== OTP Cipher %s ===\n\n", get_version()); // printf("\n\n\n\n=== OTP Cipher %s ===\n\n", get_version());
while (1) { while (1) {
show_main_menu(); show_main_menu();
@@ -275,14 +275,15 @@ int command_line_mode(int argc, char* argv[]) {
} }
void show_main_menu(void) { void show_main_menu(void) {
printf("======================== Main Menu ========================\n"); printf("\n\n\n\n=========================================== Main Menu - OTP %s \n\n", get_version());
printf("\033[4mT\033[0mext encrypt\n"); // printf("======================== Main Menu ========================\n");
printf("\033[4mF\033[0mile encrypt\n"); printf(" \033[4mT\033[0mext encrypt\n");
printf("\033[4mD\033[0mecrypt\n"); printf(" \033[4mF\033[0mile encrypt\n");
printf("\033[4mG\033[0menerate new pad\n"); printf(" \033[4mD\033[0mecrypt\n");
printf("\033[4mL\033[0mist available pads\n"); printf(" \033[4mG\033[0menerate new pad\n");
printf("\033[4mS\033[0mhow pad information\n"); printf(" \033[4mL\033[0mist available pads\n");
printf("E\033[4mx\033[0mit\n"); printf(" \033[4mS\033[0mhow pad information\n");
printf(" E\033[4mx\033[0mit\n");
printf("\nSelect option: "); printf("\nSelect option: ");
} }
@@ -336,8 +337,8 @@ int handle_encrypt_menu(void) {
// Ask user to choose between text and file encryption // Ask user to choose between text and file encryption
printf("\nSelect encryption type:\n"); printf("\nSelect encryption type:\n");
printf("1. Text message\n"); printf(" 1. Text message\n");
printf("2. File\n"); printf(" 2. File\n");
printf("Enter choice (1-2): "); printf("Enter choice (1-2): ");
char choice_input[10]; char choice_input[10];
@@ -351,9 +352,9 @@ int handle_encrypt_menu(void) {
if (choice == 1) { if (choice == 1) {
// Text encryption // Text encryption
printf("\nPad selection options:\n"); printf("\nPad selection options:\n");
printf("1. Select from numbered list\n"); printf(" 1. Select from numbered list\n");
printf("2. Enter checksum/prefix manually\n"); printf(" 2. Enter checksum/prefix manually\n");
printf("3. Browse pad files\n"); printf(" 3. Browse pad files\n");
printf("Enter choice (1-3): "); printf("Enter choice (1-3): ");
char pad_choice[10]; char pad_choice[10];
@@ -404,8 +405,8 @@ int handle_encrypt_menu(void) {
else if (choice == 2) { else if (choice == 2) {
// File encryption // File encryption
printf("\nFile selection options:\n"); printf("\nFile selection options:\n");
printf("1. Type file path directly\n"); printf(" 1. Type file path directly\n");
printf("2. Use file manager\n"); printf(" 2. Use file manager\n");
printf("Enter choice (1-2): "); printf("Enter choice (1-2): ");
char file_choice[10]; char file_choice[10];
@@ -453,8 +454,8 @@ int handle_encrypt_menu(void) {
// Ask for output format // Ask for output format
printf("\nSelect output format:\n"); printf("\nSelect output format:\n");
printf("1. Binary (.otp) - preserves file permissions\n"); printf(" 1. Binary (.otp) - preserves file permissions\n");
printf("2. ASCII (.otp.asc) - text-safe format\n"); printf(" 2. ASCII (.otp.asc) - text-safe format\n");
printf("Enter choice (1-2): "); printf("Enter choice (1-2): ");
char format_input[10]; char format_input[10];
@@ -500,8 +501,8 @@ int handle_decrypt_menu(void) {
// Ask user to choose between text/message and file decryption // Ask user to choose between text/message and file decryption
printf("\nSelect decryption type:\n"); printf("\nSelect decryption type:\n");
printf("1. Text message (ASCII armored)\n"); printf(" 1. Text message (ASCII armored)\n");
printf("2. File (.otp or .otp.asc)\n"); printf(" 2. File (.otp or .otp.asc)\n");
printf("Enter choice (1-2): "); printf("Enter choice (1-2): ");
char choice_input[10]; char choice_input[10];
@@ -1196,8 +1197,8 @@ int encrypt_text(const char* pad_identifier, const char* input_text) {
} else { } else {
// Get input text from user (interactive mode) // Get input text from user (interactive mode)
printf("\nText input options:\n"); printf("\nText input options:\n");
printf("1. Type text directly\n"); printf(" 1. Type text directly\n");
printf("2. Use text editor\n"); printf(" 2. Use text editor\n");
printf("Enter choice (1-2): "); printf("Enter choice (1-2): ");
char input_choice[10]; char input_choice[10];
@@ -1579,14 +1580,18 @@ int encrypt_file(const char* pad_identifier, const char* input_file, const char*
return 1; return 1;
} }
// Generate output filename if not specified // Generate output filename if not specified, using files directory
char default_output[512]; char default_output[512];
if (output_file == NULL) { if (output_file == NULL) {
char temp_output[512];
if (ascii_armor) { if (ascii_armor) {
snprintf(default_output, sizeof(default_output), "%s.otp.asc", input_file); snprintf(temp_output, sizeof(temp_output), "%s.otp.asc", input_file);
} else { } else {
snprintf(default_output, sizeof(default_output), "%s.otp", input_file); snprintf(temp_output, sizeof(temp_output), "%s.otp", input_file);
} }
// Apply files directory default path
get_default_file_path(temp_output, default_output, sizeof(default_output));
output_file = default_output; output_file = default_output;
} }

1
test_files_dir.txt Normal file
View File

@@ -0,0 +1 @@
Testing updated files directory functionality

1
test_new.txt Normal file
View File

@@ -0,0 +1 @@
Testing files directory functionality

BIN
test_new.txt.otp Normal file

Binary file not shown.