diff --git a/src/libecrypt.c b/src/libecrypt.c index b026a6b..ee3f178 100644 --- a/src/libecrypt.c +++ b/src/libecrypt.c @@ -5,7 +5,9 @@ #include #include -void ecrypt(int N) { +void +ecrypt_gen(int N) +{ int c = 0; int randomizer = 0; @@ -21,25 +23,73 @@ void ecrypt(int N) { for (c = 0; c < N; c++) { switch (randomizer) { - case 1: - password[c] = numbers[rand() % 10]; - randomizer = rand() % 4; - printf("%c", password[c]); - break; - case 2: - password[c] = symbols[rand() % 8]; - randomizer = rand() % 4; - printf("%c", password[c]); - break; - case 3: - password[c] = LETTER[rand() % 26]; - randomizer = rand() % 4; - printf("%c", password[c]); - break; - default: - password[c] = letter[rand() % 26]; - randomizer = rand() % 4; - printf("%c", password[c]); + case 1: + password[c] = numbers[rand() % 10]; + randomizer = rand() % 4; + printf("%c", password[c]); + break; + case 2: + password[c] = symbols[rand() % 8]; + randomizer = rand() % 4; + printf("%c", password[c]); + break; + case 3: + password[c] = LETTER[rand() % 26]; + randomizer = rand() % 4; + printf("%c", password[c]); + break; + default: + password[c] = letter[rand() % 26]; + randomizer = rand() % 4; + 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); +}