Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- /*
- * computes a password consisting of random words
- */
- int main(int argc, char* argv[])
- {
- if (argc<3){
- printf("Usage:\n%s <path to wordlist> <number of words in password>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- char* path = argv[1];
- int count = atoi(argv[2]);
- char buffer[100];
- int rand_i, lc=0;
- char c=0;
- FILE* rand = NULL;
- FILE* fp = NULL;
- /* for extra entropy use /dev/random */
- if(!(rand = fopen("/dev/urandom", "r"))) {
- printf("Failed to open /dev/urandom\n");
- exit(EXIT_FAILURE);
- }
- if(!(fp = fopen(path, "r"))) {
- printf("Failed to open %s\n", path);
- exit(EXIT_FAILURE);
- }
- /* get number of lines */
- while ((c = getc(fp)) != EOF) {
- if ( c=='\n')
- lc++;
- }
- rewind(fp);
- /* find 'count' number of words and output them */
- while(count--) {
- fread(&rand_i, sizeof(rand_i), 1, rand);
- if (rand_i<0)
- rand_i = -rand_i;
- rand_i = (rand_i % lc);
- int pos = 0;
- while(pos<rand_i) {
- c = getc(fp);
- if ( c=='\n')
- pos++;
- }
- c = 'a';
- while((c=getc(fp)) && c!='\n'){
- putchar(c);
- }
- putchar(' ');
- rewind(fp);
- }
- putchar('\n');
- fclose(fp);
- fclose(rand);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement