add checking function

This commit is contained in:
Liam Waldron 2023-05-30 10:19:12 -04:00
parent d6f3e860f6
commit 455b3481fd

View File

@ -5,7 +5,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
void ecrypt(int N) { void
ecrypt_gen(int N)
{
int c = 0; int c = 0;
int randomizer = 0; int randomizer = 0;
@ -21,25 +23,73 @@ void ecrypt(int N) {
for (c = 0; c < N; c++) { for (c = 0; c < N; c++) {
switch (randomizer) { switch (randomizer) {
case 1: case 1:
password[c] = numbers[rand() % 10]; password[c] = numbers[rand() % 10];
randomizer = rand() % 4; randomizer = rand() % 4;
printf("%c", password[c]); printf("%c", password[c]);
break; break;
case 2: case 2:
password[c] = symbols[rand() % 8]; password[c] = symbols[rand() % 8];
randomizer = rand() % 4; randomizer = rand() % 4;
printf("%c", password[c]); printf("%c", password[c]);
break; break;
case 3: case 3:
password[c] = LETTER[rand() % 26]; password[c] = LETTER[rand() % 26];
randomizer = rand() % 4; randomizer = rand() % 4;
printf("%c", password[c]); printf("%c", password[c]);
break; break;
default: default:
password[c] = letter[rand() % 26]; password[c] = letter[rand() % 26];
randomizer = rand() % 4; randomizer = rand() % 4;
printf("%c", password[c]); printf("%c", password[c]);
} }
} }
} }
int
ecrypt_check(char *firstkey, char *secondkey)
{
FILE *key1;
FILE *key2;
int cnt1 = 0;
int cnt2 = 0;
int flg = 0;
key1 = fopen(firstkey, "r");
if (key1 == NULL) {
printf("error opening %s\n", firstkey);
return 2;
}
fseek(key1, 0, SEEK_END);
cnt1 = ftell(key1);
key2 = fopen(secondkey, "r");
if (key2 == NULL) {
printf("error opening %s\n", secondkey);
return 2;
}
fseek(key2, 0, SEEK_END);
cnt1 = ftell(key2);
if (cnt1 != cnt2) {
return 1;
} else {
while (! feof(key1)) {
if (fgetc(key1) != fgetc(key2)) {
flg = 1;
break;
}
}
if (flg) {
return 1;
} else {
return 0;
}
}
fclose(key1);
fclose(key2);
}