update ecrypt_check

This commit is contained in:
Liam Waldron 2023-05-31 11:44:09 -04:00
parent b2e8d891be
commit f474115853

View File

@ -5,13 +5,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
/*
key_status
0 - keys match
1 - keys do not match
*/
int key_status;
void void
ecrypt_gen(int N) ecrypt_gen(int N)
{ {
@ -53,12 +46,6 @@ ecrypt_gen(int N)
} }
} }
/*
Return values for ecrypt_check:
0 - keys match
1 - keys do not match
2 - error opening key
*/
int int
ecrypt_check(char *firstkey, char *secondkey) ecrypt_check(char *firstkey, char *secondkey)
{ {
@ -72,8 +59,7 @@ ecrypt_check(char *firstkey, char *secondkey)
key1 = fopen(firstkey, "r"); key1 = fopen(firstkey, "r");
if (key1 == NULL) { if (key1 == NULL) {
printf("error opening %s\n", firstkey); printf("error opening %s\n", firstkey);
key_status = 2; return 1;
return key_status;
} }
fseek(key1, 0, SEEK_END); fseek(key1, 0, SEEK_END);
@ -82,16 +68,15 @@ ecrypt_check(char *firstkey, char *secondkey)
key2 = fopen(secondkey, "r"); key2 = fopen(secondkey, "r");
if (key2 == NULL) { if (key2 == NULL) {
printf("error opening %s\n", secondkey); printf("error opening %s\n", secondkey);
key_status = 2; return 1;
return key_status;
} }
fseek(key2, 0, SEEK_END); fseek(key2, 0, SEEK_END);
cnt1 = ftell(key2); cnt1 = ftell(key2);
if (cnt1 != cnt2) { if (cnt1 != cnt2) {
key_status = 1; printf("no match\n");
return key_status; return 1;
} else { } else {
while (! feof(key1)) { while (! feof(key1)) {
if (fgetc(key1) != fgetc(key2)) { if (fgetc(key1) != fgetc(key2)) {
@ -100,11 +85,11 @@ ecrypt_check(char *firstkey, char *secondkey)
} }
} }
if (flg) { if (flg) {
key_status = 1; printf("no match\n");
return key_status; return 1;
} else { } else {
key_status = 0; printf("match\n");
return key_status; return 0;
} }
} }