Last active
December 28, 2017 15:51
-
-
Save ScratchyCode/28a8c1f1102307e4dd2627b1b5427f25 to your computer and use it in GitHub Desktop.
Known the password length generates an exhaustive dictionary.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
// number of characters into charset | |
#define CHARACTERS 62 | |
// charset | |
static const char charset[] = | |
"abcdefghijklmnopqrstuvwxyz" | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
"0123456789" | |
//"\£$%&/()=!?^*-+,.-òàùè+;:_çé*@#][<>{|}" | |
; | |
int main(){ | |
int n=CHARACTERS; | |
int k, i=0, j, new_line=0, EXIT; | |
int index[k]; | |
FILE *fp; | |
fp = fopen("Passwd.txt","w"); | |
if(fp == NULL){ | |
perror("\nError"); | |
exit(1); | |
} | |
printf("\nEnter the password length: "); | |
scanf("%d",&k); | |
memset(index,0,k * sizeof(int)); | |
while(1){ | |
EXIT = 1; | |
for(i=0; i<k; i++){ | |
fprintf(fp,"%c",charset[index[i]]); | |
if(index[i] < n-1) | |
EXIT = 0; | |
} | |
fprintf(fp,"%c",'\n'); | |
if(EXIT){ | |
break; | |
} | |
++index[k-1]; | |
for(j=k-1; j>=1; j--){ | |
if(index[j] >= n){ | |
index[j] = 0; | |
++index[j-1]; | |
} | |
} | |
} | |
printf("End.\n"); | |
fflush(fp); | |
fclose(fp); | |
return 0; | |
} | |
memset(index,0,k * sizeof(int)); | |
while(1){ | |
exit = 1; | |
for(i=0; i<k; i++){ | |
fprintf(fp,"%c",charset[index[i]]); | |
if(index[i] < n-1) | |
exit = 0; | |
} | |
fprintf(fp,"%c",'\n'); | |
if(exit){ | |
break; | |
} | |
++index[k-1]; | |
for(j=k-1; j>=1; j--){ | |
if(index[j] >= n){ | |
index[j] = 0; | |
++index[j-1]; | |
} | |
} | |
} | |
printf("\nEnd.\n"); | |
fflush(fp); | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment