#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define CHARLANG 96
FILE *fp; /*文件指针*/
char* join3(char *s1, char *s2)
{
char *result = malloc(strlen(s1)+strlen(s2)+1);//+1 for the zero-terminator
//in real code you would check for errors in malloc here
strcpy(result, s1);
strcat(result, s2);
return result;
}
char *create(int num){
char str[100];
itoa(num, str, 10);
char p[5] =".txt";
return join3(str,p);
}
int full(int a,int *b){
int i=0;
int count=0;
while(i<a){
if(b[i]!=0){
count++;
}
i++;
}
if(count==0){
return 1;
}else {
return 0;
}
}
void add(int a,int *b){
int i=0;
b[0]++;
while(i<a){
if(b[i]>=CHARLANG){
b[i]=0;
b[i+1]++;
}
i++;
}
}
void out(int a,int *b, char *c){
int i=0;
for(i=0;i<a;i++){
fprintf(fp,"%c",c[b[i]]);
printf("%c",c[b[i]]);
}
fprintf(fp,"\n");
printf("\n");
}
int main()
{ char a[CHARLANG]="0123456789abcdefghjijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ[]~.',/\\:!?@#$%^&*()<>_+|~`{ }-;\"";
int b[20]={0};
int i=0;
int j=0;//字典长度
int k=5000;//字典分割长度
int l=0;
int num=1;
printf("请输入字典长度");
scanf("%d",&j);
fp = fopen("1.txt","w");
while(1){
out(j,b,a);
add(j,b);
if(full(j,b)==1){
fclose(fp); /*关闭文件*/
break;
}
l++;
if(l%k==k-1){
fclose(fp); /*关闭文件*/
num++;
fp = fopen(create(num),"w");
}
}
fclose(fp); /*关闭文件*/
printf("生成成功");
system("pause");
return 0;
}
C语言 破解字典生成器
最新推荐文章于 2024-08-21 17:06:07 发布