/* libecrypt - library for including ecrypt functions in programs */ #include #include #include #include void ecrypt_gen(int N) { int c = 0; int randomizer = 0; srand((unsigned int)(time(NULL))); char numbers[] = "1234567890"; char letter[] = "qwertyuiopasdfghjklzxcvbnm"; char LETTER[] = "QWERTYUIOPASDFGHJKLZXCVBNM"; char symbols[] = "!@#$%^&*?"; char password[N]; randomizer = rand() % 4; 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]); } } } 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 1; } fseek(key1, 0, SEEK_END); cnt1 = ftell(key1); key2 = fopen(secondkey, "r"); if (key2 == NULL) { printf("error opening %s\n", secondkey); return 1; } fseek(key2, 0, SEEK_END); cnt2 = ftell(key2); fseek(key1, 0, SEEK_SET); fseek(key2, 0, SEEK_SET); if (cnt1 != cnt2) { printf("no match\n"); return 1; } else { while (! feof(key1)) { if (fgetc(key1) != fgetc(key2)) { flg = 1; break; } } if (flg) { printf("no match\n"); exit(1); } else { printf("match\n"); exit(0); } } fclose(key1); fclose(key2); }