fix return values

This commit is contained in:
Liam Waldron 2023-05-30 13:27:17 -04:00
parent 7dca4b5841
commit fe3eb0c31d

View File

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