Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- FILE *file;
- void writeFile(const char* buffer, size_t buffer_len) {
- assert(file);
- fwrite(buffer, sizeof(char), buffer_len, file);
- fputc('\n', file);
- }
- void gain(char* buffer, size_t buffer_idx, int remain_length);
- inline void put_symbol(char* buffer, size_t buffer_idx, int remain_length, char symbol)
- {
- buffer[buffer_idx] = symbol;
- buffer_idx++;
- if (remain_length > 0)
- {
- gain(buffer, buffer_idx, remain_length - 1);
- } else {
- writeFile(buffer, buffer_idx);
- }
- }
- void gain(char* buffer, size_t buffer_size, int remain_length)
- {
- char i;
- for (i = 'a'; i <= 'z'; i++)
- put_symbol(buffer, buffer_size, remain_length, i);
- for (i = '0'; i <= '9'; i++)
- put_symbol(buffer, buffer_size, remain_length, i);
- for (i = 'A'; i <= 'Z'; i++)
- put_symbol(buffer, buffer_size, remain_length, i);
- char* symbols = "[]*.:;' \"|0";
- for (i = 0; symbols[i] != 0; i++)
- put_symbol(buffer, buffer_size, remain_length, symbols[i]);
- }
- int main(int argc, char** argv)
- {
- if (argc <= 1)
- {
- fprintf(stderr, "Error: you must set password length\n");
- } else {
- file = fopen("passlist.txt", "w");
- if (argc == 2) {
- int password_length = atoi(argv[1]);
- char* buffer = malloc(sizeof(char) * (password_length));
- gain(buffer, 0, password_length - 1);
- } else if (argc == 3) {
- int min_password_length = atoi(argv[1]);
- int max_password_length = atoi(argv[2]);
- char *buffer = malloc(sizeof(char) * max_password_length);
- for (int i = min_password_length - 1; i < max_password_length; i++)
- {
- gain(buffer, 0, i);
- printf("Generated passwords with length: %i", i + 1);
- }
- }
- }
- if (file)
- fclose(file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement