改进版的《黑客字典》VC++源码
黑客字典2.2,改进了穷举的算法,密码最大长度为1000,使代码长度减小,程序的执行速度加快。
同时加入了新的功能,除了完成一般黑客字典的所有功能外. 还加入了辅助功能,协助黑客更好的
设置字典。
常规字典:
01。生日字典,提供12种格式。
02。手机。电话字典。
03。穷举给定长度的数字,大小写字母之间的排列。
04。支持字定义字符模式。
辅助功能:
05。增加了无穷个字典的合并功能,合并后可去除每两个字典档中重复的密码。
06。把一个较大的文件分解成若干个小的字典档。
07。向一个文件每个密码的前面或后面增加特定的字符串,或是删除特定的字符串。
08。把每个密码的前后调换。
09。从一个文件过滤出特定字符的密码。
10。可以将指定文件中每行指定的字符前面的字符保留。
11。将一个文件中每行中指定的字符串替换成另一个字符串。
12。完成类似txt2dic程式的功能,从指定程序过滤掉给定的字符串。
02.当穷举时,如果有'^',需在命令行下写两便。例如:@#^^,将生成@#^之间所有的排列。
---------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 1000
#define Max 100
#define M 600
void help(void);
void turn(char *,char *); /*将密码倒转*/
void grep(char *,char *,char *); /*保留特定字符串*/
void find(char *,char *,char *); /*查找字符函数*/
void a_file(int,char **);
void c_file(int,char **);
void mobi(char *,char *,char *,char *,char *); /*生成手机密码*/
void tel(char *,char *,char *,char *); /*电话密码*/
void create(char *,char *,char *,char *); /*穷举密码*/
void adle(char *,char *,char *,char *); /*文件每行加入特定的字符串*/
void acle(char *,char *,char *,char *); /*文件每行删除特定的字符串*/
void cut(char *,char *,char *,char *); /*保留文件每行中特定字符前面的字符串*/
void txt2dic(char *,char *,char *,char *); /*过滤特定字符串*/
void defi(char *,char *,char *,char *); /*将指定的字符串替换成另一字符串*/
void birth(char *,char *,char *,char *,char *,char *,char *,char *); /*生日字典*/
char a[MAX]; /*将要穷举的字符数组*/
char line[MAX][Max];
char b[]="0123456789";
char c[]="abcdefghijklmnopqrstuvwxyz";
char d[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char e[]="0123456789abcdefghijklmnopqrstuvwxyz";
char h[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char g[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char f[]="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(int argc ,char **argv)
{
FILE *fp1,*fp2,*fp3;
long lenth1=0,len1=0;
long sum=0,len2,len3;
long lenth=0;
int i,j;
int flag=1;
char line1[M],line2[M];
char ch;
if(argc==1)
{
help();
}
if(!strcmp(argv[1],"-tt"))
{
txt2dic(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-g"))
{
grep(argv[2],argv[3],argv[4]);
}
if(!strcmp(argv[1],"-m"))
{
mobi(argv[2],argv[3],argv[4],argv[5],argv[6]);
}
if(!strcmp(argv[1],"-t"))
{
tel(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-b"))
{
birth(argv[2],argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9]);
}
if(!strcmp(argv[1],"-d"))
{
create(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-ac"))
{
adle(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-ca"))
{
acle(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-u"))
{
turn(argv[2],argv[3]);
}
if(!strcmp(argv[1],"-cc"))
{
cut(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-v"))
{
defi(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-a")) /*字典文件合并*/
{
a_file(argc,argv);
}
if(!strcmp(argv[1],"-c")) /*字典文件分割*/
{
c_file(argc,argv);
}
}
void mobi(char *a,char *b,char *c,char *d,char *e) /*手机字典生成函数*/
{
FILE *fp;
char *aa=a;
char *bb=b;
char *cc=c;
char *dd=d;
char *ee=e;
char ch;
int p,q,j;
long m,n,i;
long lenth=0;
if((fp=fopen(aa,"w+"))==NULL)
{
printf("Can't open the file %s\n",aa);
exit(0);
}
p=atoi(bb);
q=atoi(cc);
m=atol(dd);
n=atol(ee);
if(p>q||m>n) /*排错处理*/
{
printf("error,p must <= q or m <= n please input again:\n");
exit(0);
}
for(j=p;j<=q;j++)
for(i=m;i<=n;i++)
fprintf(fp,"%d%ld\n",j,i,fp);
rewind(fp);
while((ch=fgetc(fp))!=EOF)
{
if(ch=='\n')
++lenth;
}
printf("done.\nthe file has %ld words in %s\n",lenth,aa);
fclose(fp);
}
void tel(char *a,char *b,char *c,char *d) /*电话字典生成函数*/
{
FILE *fp;
char *aa=a,*bb=b,*cc=c,*dd=d;
int p,w=0;
char ch;
long m,n,i;
long lenth=0;
if((fp=fopen(aa,"w+"))==NULL)
{
printf("Can't open the file %s\n",aa);
exit(0);
}
p=atoi(bb);
m=atol(cc);
n=atol(dd);
if(m>=n)
{
printf("error.start_n must <= end_n\n");
exit(0);
}
if(p>=1000)
{
for(i=m;i<=n;i++)
fprintf(fp,"%d%ld\n",p,i);
}
else
{
for(i=m;i<=n;i++)
fprintf(fp,"%d%d%ld\n",w,p,i);
}
rewind(fp);
while((ch=fgetc(fp))!=EOF)
{
if(ch=='\n')
++lenth;
}
fclose(fp);
printf("\nDone.\nThe file has %ld hang in %s.\n",lenth,aa);
}
void birth(char *a1,char *b1,char *c1,char *d1,char *e1,char *f1,char *g1,char *h1)
{
FILE *fp;
char *aa=a1,*bb=b1,*cc=c1,*dd=d1,*ee=e1,*ff=f1,*gg=g1,*hh=h1;
long int lenth=0;
int a,b,c,d,e,f,h,m=0;
char ch,ch1='//',ch2=':',ch3='.',ch4='-',ch5='\\';
if((fp=fopen(bb,"w+"))==NULL)
{
printf("Can't open the file %s.\n",bb);
exit(0);
}
h=atoi(aa);
a=atoi(cc);
b=atoi(dd);
c=atoi(ee);
d=atoi(ff);
e=atoi(gg);
f=atoi(hh);
if(a>d||b>e||c>f)
{
printf("error.check it again.\n");
exit(0);
}
while(a<=d)
{
switch(h)
{
case 1:
if(b<10&&c<10)
fprintf(fp,"%d%d%d%d%d\n",a,m,b,m,c);
if(b>=10&&c<10)
fprintf(fp,"%d%d%d%d\n",a,b,m,c);
if(b<10&&c>=10)
fprintf(fp,"%d%d%d%d\n",a,m,b,c);
if(b>=10&&c>=10)
fprintf(fp,"%d%d%d\n",a,b,c);
break;
case 2:
if(b<10&&c<10)
fprintf(fp,"%d%c%d%d%c%d%d\n",a,ch1,m,b,ch1,m,c);
if(b>=10&&c<10)
fprintf(fp,"%d%c%d%c%d%d\n",a,ch1,b,ch1,m,c);
if(b<10&&c>=10)
fprintf(fp,"%d%c%d%d%c%d\n",a,ch1,m,b,ch1,c);
if(b>=10&&c>=10)
fprintf(fp,"%d%c%d%c%d\n",a,ch1,b,ch1,c);
break;
case 3:
if(b<10&&c<10)
fprintf(fp,"%d%c%d%d%c%d%d\n",a,ch2,m,b,ch2,m,c);
if(b>=10&&c<10)
fprintf(fp,"%d%c%d%c%d%d\n",a,ch2,b,ch2,m,c);
if(b<10&&c>=10)
fprintf(fp,"%d%c%d%d%c%d\n",a,ch2,m,b,ch2,c);
if(b>=10&&c>=10)
fprintf(fp,"%d%c%d%c%d\n",a,ch2,b,ch2,c);
break;
case 4:
if(b<10&&c<10)
fprintf(fp,"%d%c%d%d%c%d%d\n",a,ch3,m,b,ch3,m,c);
if(b>=10&&c<10)
fprintf(fp,"%d%c%d%c%d%d\n",a,ch3,b,ch3,m,c);
if(b<10&&c>=10)
fprintf(fp,"%d%c%d%d%c%d\n",a,ch3,m,b,ch3,c);
if(b>=10&&c>=10)
fprintf(fp,"%d%c%d%c%d\n",a,ch3,b,ch3,c);
break;
case 5:
if(b<10&&c<10)
fprintf(fp,"%d%c%d%d%c%d%d\n",a,ch4,m,b,ch4,m,c);
if(b>=10&&c<10)
fprintf(fp,"%d%c%d%c%d%d\n",a,ch4,b,ch4,m,c);
if(b<10&&c>=10)
fprintf(fp,"%d%c%d%d%c%d\n",a,ch4,m,b,ch4,c);
if(b>=10&&c>=10)
fprintf(fp,"%d%c%d%c%d\n",a,ch4,b,ch4,c);
break;
case 6:
fprintf(fp,"%d%d%d\n",a,b,c);
break;
case 7:
fprintf(fp,"%d%c%d%c%d\n",a,ch1,b,ch1,c);
break;
case 8:
fprintf(fp,"%d%c%d%c%d\n",a,ch2,b,ch2,c);
break;
case 9:
fprintf(fp,"%d%c%d%c%d\n",a,ch3,b,ch3,c);
break;
case 10:
fprintf(fp,"%d%c%d%c%d\n",a,ch4,b,ch4,c);
break;
case 11:
fprintf(fp,"%d%c%d%c%d\n",a,ch5,b,ch5,c);
break;
case 12:
if(b<10&&c<10)
fprintf(fp,"%d%c%d%d%c%d%d\n",a,ch5,m,b,ch5,m,c);
if(b>=10&&c<10)
fprintf(fp,"%d%c%d%c%d%d\n",a,ch5,b,ch5,m,c);
if(b<10&&c>=10)
fprintf(fp,"%d%c%d%d%c%d\n",a,ch5,m,b,ch5,c);
if(b>=10&&c>=10)
fprintf(fp,"%d%c%d%c%d\n",a,ch5,b,ch5,c);
break;
}
c++;
if(a==d)
{
if(b>=e&&c>f)
break;
}
if(c>31)
{
b++;
c=1;
if(b>12)
{
a++;
b=1;
}
}
}
rewind(fp);
while((ch=fgetc(fp))!=EOF)
{
if(ch=='\n')
lenth++;
}
fclose(fp);
printf("\ndone.\nThe file has %ld hang in %s\n",lenth+1,bb);
}
void a_file(int len,char **line)
{
FILE *s_fp,*t_fp;
int i=2;
int flag=1;
long int lenth=0;
long int sum=0;
char buffer[Max];
char buffer1[Max];
char ch;
char ch1='\n';
if((s_fp=fopen(line,"w+"))==NULL)
{
printf("Can't open the file %s.\n",line);
exit(0);
}
if((t_fp=fopen(line[i+1],"a"))==NULL)
{
printf("Can't open the file %s.\n",line[i+1]);
exit(0);
}
fseek(t_fp,-1L,2);
if((ch=fgetc(t_fp))!='\n')
{
printf("%c\n",ch);
fputs("\n",t_fp);
}
fclose(t_fp);
if((t_fp=fopen(line[i+1],"r"))==NULL)
{
printf("Can't open the file %s.\n",line[i+1]);
exit(0);
}
while(fgets(buffer,512,t_fp)!=NULL)
{
fputs(buffer,s_fp);
++lenth;
}
rewind(s_fp);
fclose(t_fp);
printf("The file %s has %ld words\n\n",line[i+1],lenth);
printf("waiting...\n");
for(i=4;i<len;i++)
{
lenth=0;
if((t_fp=fopen(line,"r"))==NULL)
{
printf("Can't open the file %s.\n",line);
exit(0);
}
while(fgets(buffer,512,t_fp)!=NULL)
{
++lenth;
rewind(s_fp);
while(fgets(buffer1,512,s_fp)!=NULL)
{
if(!strcmp(buffer,buffer1))
{
flag=1;
break;
}
}
if(flag==1)
flag=0;
else
fputs(buffer,s_fp);
}
fputs("\n",s_fp);
fclose(t_fp);
printf("The file %s has %ld words.\n\n",line,lenth);
printf("waiting...\n");
}
rewind(s_fp);
while(fgets(buffer,512,s_fp)!=NULL)
++sum;
fclose(s_fp);
printf("The file %s has %ld words.\n\n",line[2],sum);
printf("done.\n\nGood Luck:)\n");
}
void c_file(int len,char **line)
{
FILE *s_fp,*t_fp;
int i=2,j;
long int lenth=0,len1,len2,len3=0;
char buffer[Max];
char ch;
if((s_fp=fopen(line,"r"))==NULL)
{
printf("Can't open the file %s.\n");
exit(0);
}
while((ch=fgetc(s_fp))!=EOF)
if(ch=='\n')
lenth++;
rewind(s_fp);
len1=lenth/(len-3);
len2=lenth%(len-3);
for(i=3;i<len;i++)
{
if((t_fp=fopen(line,"w+"))==NULL)
{
printf("Can't open the file %s.\n",line);
exit(0);
}
for(j=len3;j<len1;j++)
{
fgets(buffer,512,s_fp);
fputs(buffer,t_fp);
}
fclose(t_fp);
printf("finished file %s.\n",line);
len3=len1;
if(i==len)
{
len1+=len1;
len1+=len2;
}
len1+=len1;
}
}
void create(char *aa,char *bb,char *cc,char *dd) /*穷举算法*/
{
FILE *fp;
char *a1=aa,*b2=bb,*c2=cc,*d2=dd,ch;
char a2[MAX],line[MAX],up[MAX];
int min,max,min1,max1,next,lenth;
register int i=0,j;
long lenth1=0;
min=atoi(c2);
max=atoi(d2);
if(min>max)
{
printf("argv[3] must <= argv[4].\n");
exit(0);
}
if(!strcmp(a1,"-s"))
strcpy(a,c);
else if(!strcmp(a1,"-b"))
strcpy(a,d);
else if(!strcmp(a1,"-n"))
strcpy(a,b);
else if(!strcmp(a1,"-sn"))
strcpy(a,e);
else if(!strcmp(a1,"-bn"))
strcpy(a,h);
else if(!strcmp(a1,"-sb"))
strcpy(a,g);
else if(!strcmp(a1,"-sbn"))
strcpy(a,f);
else
{
strcpy(a,a1);
}
if((fp=fopen(b2,"w+"))==NULL)
{
printf("Can't open the file.\n");
exit(0);
}
puts(a);
lenth=strlen(a);
while(min<=max)
{
for(i=0;i<max;i++)
up=0;
next=1;
while(next)
{
for(i=0;i<min;i++) /*注意密码下标*/
line=a[up];
line='\0';
fputs(line,fp); fputs("\n",fp);
for(j=min-1;j>=0;j--)
{
up[j]++; /*下标进位,穷举算法的关键*/
if(up[j]!=lenth)
break;
else
{
up[j]=0;
if(j==0) next=0;
}
}
}
min++;
}
rewind(fp);
while((ch=fgetc(fp))!=EOF)
{
if(ch=='\n')
++lenth1;
}
fclose(fp);
printf("\n");
printf("Done.\nThe file has %ld hang in %s.\n",lenth1,bb);
}
void adle(char *aa,char *b,char *c,char *d) /*文件每行前或后增加特定的字符串*/
{
FILE *fp,*fp1;
char *aaa=aa,*bb=b,*cc=c,*dd=d;
char line1[600];
int len,i;
if((fp=fopen(cc,"r"))==NULL)
{
printf("Can't open the file %s\n",cc);
exit(0);
}
if((fp1=fopen(dd,"w+"))==NULL)
{
printf("Can't open the file %s\n",dd);
exit(0);
}
while(fgets(line1,512,fp)!=NULL)
{
if(!strcmp(aaa,"-a"))
{
fputs(bb,fp1);
fputs(line1,fp1);
}
if(!strcmp(aaa,"-c"))
{
len=strlen(line1);
for(i=0;i<(len-1);i++)
fputc(line1,fp1);
fputs(bb,fp1);
fputs("\n",fp1);
}
}
fclose(fp1);
fclose(fp);
printf("done.\n");
}