Compare commits

...

2 Commits

68
otp.c
View File

@@ -132,41 +132,41 @@ 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()); char input[10];
while (1) { while (1) {
show_main_menu(); show_main_menu();
char input[10];
if (fgets(input, sizeof(input), stdin)) {
char choice = toupper(input[0]);
switch (choice) { if (!fgets(input, sizeof(input), stdin)) {
case 'T': printf("Goodbye!\n");
handle_text_encrypt(); break;
break; }
case 'F':
handle_file_encrypt(); char choice = toupper(input[0]);
break;
case 'D': switch (choice) {
handle_decrypt_menu(); case 'T':
break; handle_text_encrypt();
case 'P': break;
handle_pads_menu(); case 'F':
break; handle_file_encrypt();
case 'X': break;
case 'Q': case 'D':
printf("Goodbye!\n"); handle_decrypt_menu();
return 0; break;
default: case 'P':
printf("Invalid option. Please select T, F, D, P, or X.\n"); handle_pads_menu();
continue; break;
} case 'X':
} else { printf("Goodbye!\n");
printf("Error reading input. Please try again.\n"); return 0;
continue; default:
printf("Invalid choice. Please try again.\n");
break;
} }
printf("\n");
} }
return 0;
} }
int command_line_mode(int argc, char* argv[]) { int command_line_mode(int argc, char* argv[]) {
@@ -767,7 +767,7 @@ int list_available_pads(void) {
chksum[64] = '\0'; chksum[64] = '\0';
// Get pad file size // Get pad file size
char full_path[300]; // Increased buffer size to accommodate longer paths char full_path[1024]; // Increased buffer size to accommodate longer paths
snprintf(full_path, sizeof(full_path), "%s/%s", current_pads_dir, entry->d_name); snprintf(full_path, sizeof(full_path), "%s/%s", current_pads_dir, entry->d_name);
struct stat st; struct stat st;
if (stat(full_path, &st) == 0) { if (stat(full_path, &st) == 0) {
@@ -2095,7 +2095,7 @@ int decrypt_ascii_file(const char* input_file, const char* output_file) {
} }
int read_state_offset(const char* pad_chksum, uint64_t* offset) { int read_state_offset(const char* pad_chksum, uint64_t* offset) {
char state_filename[MAX_HASH_LENGTH + 20]; char state_filename[1024];
snprintf(state_filename, sizeof(state_filename), "%s/%s.state", current_pads_dir, pad_chksum); snprintf(state_filename, sizeof(state_filename), "%s/%s.state", current_pads_dir, pad_chksum);
FILE* state_file = fopen(state_filename, "rb"); FILE* state_file = fopen(state_filename, "rb");
@@ -2115,7 +2115,7 @@ int read_state_offset(const char* pad_chksum, uint64_t* offset) {
} }
int write_state_offset(const char* pad_chksum, uint64_t offset) { int write_state_offset(const char* pad_chksum, uint64_t offset) {
char state_filename[MAX_HASH_LENGTH + 20]; char state_filename[1024];
snprintf(state_filename, sizeof(state_filename), "%s/%s.state", current_pads_dir, pad_chksum); snprintf(state_filename, sizeof(state_filename), "%s/%s.state", current_pads_dir, pad_chksum);
FILE* state_file = fopen(state_filename, "wb"); FILE* state_file = fopen(state_filename, "wb");
@@ -2289,8 +2289,8 @@ void get_default_file_path(const char* filename, char* result_path, size_t resul
} }
void get_pad_path(const char* chksum, char* pad_path, char* state_path) { void get_pad_path(const char* chksum, char* pad_path, char* state_path) {
snprintf(pad_path, MAX_HASH_LENGTH + 20, "%s/%s.pad", current_pads_dir, chksum); snprintf(pad_path, 1024, "%s/%s.pad", current_pads_dir, chksum);
snprintf(state_path, MAX_HASH_LENGTH + 20, "%s/%s.state", current_pads_dir, chksum); snprintf(state_path, 1024, "%s/%s.state", current_pads_dir, chksum);
} }
// OTP thumb drive detection function implementation // OTP thumb drive detection function implementation