diff --git a/src/main.c b/src/main.c index 36d56d5..0d0d8d1 100644 --- a/src/main.c +++ b/src/main.c @@ -10,17 +10,17 @@ #define ALPHABET "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM[]{}<>()*#" #define HELP_MESSAGE "\tpwdgen - generates a password of the given size from the standard alphabet\n"\ - "\tpwdgen - generates four characters from the given alphabet\n"\ - "\tpwdgen - generates a password of the given length from the given alphabet\n"\ - "\tpwdgen - generates a four character password from the standard alphabet\n" + "\tpwdgen - generates four characters from the given alphabet\n"\ + "\tpwdgen - generates a password of the given length from the given alphabet\n"\ + "\tpwdgen - generates a four character password from the standard alphabet\n" char *get_random_string(const char *alphabet, int quantity) { - srand(time(NULL)); - char *str = malloc(sizeof(char*) * quantity); - for (int i = 0; i < quantity; i++) { - str[i] = alphabet[0+rand()%strlen(alphabet)]; - } - return str; + srand(time(NULL)); + char *str = malloc(sizeof(char *) * quantity); + for (int i = 0; i < quantity; i++) { + str[i] = alphabet[0 + rand() % strlen(alphabet)]; + } + return str; } // char *get_file_extension(char *filename) { @@ -49,56 +49,56 @@ char *get_random_string(const char *alphabet, int quantity) { // } int main(int argc, char *argv[]) { - if (argc == 2) { - if (!strcmp(argv[1], "-h")) { - printf("%s\n", HELP_MESSAGE); - return 0; - } else if (atoi(argv[1]) > 0) { - int quantity = atoi(argv[1]); - char *pwd = get_random_string(ALPHABET, quantity); - printf("Password -> %s\n", pwd); - return 0; - } else if (atoi(argv[1]) == 0) { - // char *file_extension = get_file_extension(argv[1]); - // printf("%s\n", file_extension); - // printf("%s\n%d\n%d\n", argv[1], strcmp(file_extension, ""), strcmp(file_extension, "txt")); - // if (!strcmp(file_extension, "txt")) { - // FILE *alphabet_file = fopen(argv[1], "r"); - // if (alphabet_file == NULL) { - // printf("Can't open file\n"); - // return 1; - // } - // int64_t size = getFileSize(alphabet_file); - // // printf("%ld\n", size); - // char alphabet[size]; - // fgets(alphabet, size+1, alphabet_file); - // for (int i = 0; i < size; i++){ - // if (alphabet[i] == '\n') { - // printf("nononono"); - // }else { - // printf("%c\n", alphabet[i]); - // } - // } - // fclose(alphabet_file); - // char *pwd = get_random_string(alphabet, 4); - // printf("Password -> %s\n", pwd); - // } - // printf("%s\n", get_file_extension(argv[1])); - char *pwd = get_random_string(argv[1], 4); - printf("Password -> %s\n", pwd); - return 0; - } - } - if (argc == 3) { - int quantity = atoi(argv[2]); - char *alphabet = argv[1]; - char *pwd = get_random_string(alphabet, quantity); - printf("Password -> %s\n", pwd); - return 0; - } - char *pwd = get_random_string(ALPHABET, 4); - printf("Password -> %s\n", pwd); - return 0; + if (argc == 2) { + if (!strcmp(argv[1], "-h")) { + printf("%s\n", HELP_MESSAGE); + return 0; + } else if (atoi(argv[1]) > 0) { + int quantity = atoi(argv[1]); + char *pwd = get_random_string(ALPHABET, quantity); + printf("Password -> %s\n", pwd); + return 0; + } else if (atoi(argv[1]) == 0) { + // char *file_extension = get_file_extension(argv[1]); + // printf("%s\n", file_extension); + // printf("%s\n%d\n%d\n", argv[1], strcmp(file_extension, ""), strcmp(file_extension, "txt")); + // if (!strcmp(file_extension, "txt")) { + // FILE *alphabet_file = fopen(argv[1], "r"); + // if (alphabet_file == NULL) { + // printf("Can't open file\n"); + // return 1; + // } + // int64_t size = getFileSize(alphabet_file); + // // printf("%ld\n", size); + // char alphabet[size]; + // fgets(alphabet, size+1, alphabet_file); + // for (int i = 0; i < size; i++){ + // if (alphabet[i] == '\n') { + // printf("nononono"); + // }else { + // printf("%c\n", alphabet[i]); + // } + // } + // fclose(alphabet_file); + // char *pwd = get_random_string(alphabet, 4); + // printf("Password -> %s\n", pwd); + // } + // printf("%s\n", get_file_extension(argv[1])); + char *pwd = get_random_string(argv[1], 4); + printf("Password -> %s\n", pwd); + return 0; + } + } + if (argc == 3) { + int quantity = atoi(argv[2]); + char *alphabet = argv[1]; + char *pwd = get_random_string(alphabet, quantity); + printf("Password -> %s\n", pwd); + return 0; + } + char *pwd = get_random_string(ALPHABET, 4); + printf("Password -> %s\n", pwd); + return 0; } // int64_t getFileSize(const char* file_name){