Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
C Expert Help
This is where it goes crazy: brute is called with the length of the string, and the filename to output to. "null" is passed for filename if it isn't being written. Run the code, and you'll see that it really doesn't do what you'd expect.
void brute(int length,char *file){
if(file!="null"){
out=fopen(file,"w");
}
char pass[length];
int x;
int y;
printf("Brute.Length= %d\n",length);
printf("Brute.File=%s\n",file);
while(done(pass)==0){
for(x=0;x<length;x++){
y=pass[x];
if(y==0){
pass[x]=48;
}
if(y>122 && x!=length){
pass[x]=48;
pass[x+1]++;
}
pass[x]++;
}
printf("Key: %s\n",pass);
if(file!="null")
fprintf(out,"Key: %s\n",pass);
}
if(file!="null")
fclose(out);
}
The error is in the algorithm, each cycle increases all chars in pass. pass = 000, 111, 222, … It also overwrites the null terminator, giving gibberish in the output.
This code gives proper output:
#define LOW 48
#define HIGH 122
void brute(int length, char *file) {
char pass[length+1];
int x, f;
FILE* out;
f = !strcmp(file, "null");
if(f)
out=fopen(file,"w");
for(x=0;x<length;x++)
pass[x]=LOW;
pass[length]=0;
printf("Brute.Length= %d\n",length);
printf("Brute.File= %s\n",file);
while(done(pass)==0) {
printf("Key: %s\n",pass);
if(f)
fprintf(out,"Key: %s\n",pass);
for(x=0;x<length;x++) {
if(pass[x]++<=HIGH)
break;
pass[x]=LOW;
}
if(x==length)
break;
}
if(f)
fclose(out);
}