一个简单的字典工具(C++源码)

[原创]一个简单的字典工具(C++源码)
文章标题:[原创]一个简单的字典工具(C++源码)顶部 chris7 发布于:2005-08-2216:06 [楼主][原创]一个简单的字典工具(C++源码)
文章作者:chris7
信息来源:邪恶八进制信息安全团队技术论坛

目前实现的主要功能:
1.制作字典
1.1向导模式
1.2自定义模式
2.对字典进行加工
2.1给字典中的密码添加前缀
2.2给字典中的密码添加后缀
2.3合并多个字典
 一些工具仅支持单个字典
2.4过滤指定字典中的重复密码
 合并后的字典可能会出现重复密码

如果处理比较大的字典
由于未使用多线程处理
速度会比较慢
尤其体现在过滤功能上
因为没想到更好的算法

之所以用C++而不是C来实现
是因为C++的I/O流与C的I/O函数相比
更强大易用和安全
不过相应的缺点是效率要低一点

程序如下(VC++6.0编译通过):


Copycode
#include
#include
usingnamespacestd;
#defineMaxCharNum256
#defineMaxPassLen64
#defineMaxFileNameLen32
#defineMaxFileNum16

//一些全局变量
structFlags{
boolNumbers;
boolSmallLetters;
boolCapitalLetters;
boolSpecialCharacters;
};
Flagsflags={false,false,false,false};//使用全局标志来简化程序实现
boolUserDefined;
charchars[MaxCharNum];//全局数组
charpass[MaxPassLen];

voidGuide();//提供选择,并设置相应标志
voidBuild();//生成字典
voidGetPass(intstrlen,intpasslen,intnow,ofstream&fout);//递归函数,生成定长密码
voidAdvanced();//提供高级功能的选择菜单
voidAddPrefix();//添加前缀
voidAddSuffix();//添加后缀
voidJoin();//合并字典
voidFilter();//过滤重复密码
voidByeBye();//退出程序运行

voidmain(){
cout<<<" "
<<"Welcometo7dicV1.0"<<<" "
<<"Codebychris7"<<<" "
<<"Fineshedat2005-8-21"<<<" "
<<"E-mail:[email]technevol@https://www.360docs.net/doc/4112755676.html,[/email]"<<<" "
<<"Blog:https://www.360docs.net/doc/4112755676.html,"<Label:
charchoice;
cout<<<"Pleaseselectoneofthefollows:"<<<"1.Makeadictionary"<<<"2.Advancedtools"<<<"3.Exit"<<<"Pleaseenteryourchoice(1to3):";
do{
cin>>choice;
switch(choice){
case'1':
Guide();
Build();
break;
case'2':
Advanced();
break;
case'3':
ByeBye();
default:
cout<<"BadInput!Tryagain:";
}
}while(choice<'1'||choice>'3');

cout<<<"Pleaseselectoneofthefollows:"<<<"1.Backtothetopmenu"<<<"2.Terminateme"<<<"Pleaseenteryourchoice(1to2):";
do{
cin>>choice;
switch(choice){
case'1':
gotoLabel;
break;
case'2':
ByeBye();
default:
cout<<"BadInput!T

ryagain:";
}
}while(choice<'1'||choice>'2');
}

voidGuide(){
cout<<<"Pleaseselectonemodel:"<<<"1.GuideModel"<<<"https://www.360docs.net/doc/4112755676.html,er-definedModel"<<<"3.Exit"<<<"Pleaseenteryourchoice(1to3):";

charchoice;
do{
cin>>choice;
switch(choice){
case'1':
cout<<<"Pleaseselectcharactersneeded:"<<<"1.AllNumbers(0to9)"<<<"2.AllSmallLetters(atoz)"<<<"3.AllCapitalLetters(AtoZ)"<<<"4.AllPrintedSpecialCharacters"<<<"Pleaseentersomeofthenumbersabove:";

getchar();
charnums[MaxCharNum];
inti;
boolerr;
do{
gets(nums);
err=false;
for(i=0;iif(err==true)break;
switch(nums[i]){
case'1':
flags.Numbers=true;break;
case'2':
flags.SmallLetters=true;break;
case'3':
flags.CapitalLetters=true;break;
case'4':
flags.SpecialCharacters=true;break;
case'':
break;
default:
cout<<"BadInput!Tryagain:";
err=true;
}
}
}while(err);
break;
case'2':
UserDefined=true;
cout<<<"Pleaseenterallthecharactersthatyouselect(lessthan"<<getchar();
gets(chars);
break;
case'3':
ByeBye();
default:
cout<<"BadInput!Tryagain:";
}
}while(choice<'1'||choice>'3');
}

voidBuild(){
intmaxpasslen;
cout<<<"Pleaseenterthemaximumlenthofthepassword:";
cin>>maxpasslen;

intlen;
chartmp;
if(UserDefined==true){
len=strlen(chars);
for(inti=1;ifor(intj=0;jif(chars[i]==chars[j]){
chars[i]=chars[len-1];
chars[len-1]='\0';
len--;
i--;
}
}
}
}
else{
len=0;
if(flags.Numbers==true)for(tmp='0';tmp<='9';tmp++)chars[len++]=tmp;
if(flags.SmallLetters==true)for(tmp='a';tmp<='z';tmp++)chars[len++]=tmp;
if(flags.CapitalLetters==true)for(tmp='A';tmp<='Z';tmp++)chars[len++]=tmp;
if(flags.SpecialCharacters==true){
for(tmp='';tmp<'0';tmp++)chars[len++]=tmp;
for(tmp=':';tmp<'A';tmp++)chars[len++]=tmp;
for(tmp='[';tmp<'a';tmp++)chars[len++]=tmp;
for(tmp='{';tmp<='~';tmp++)chars[len++]=tmp;
}
chars[len]='\0';
}

ofstreamfout("7.dic");
if(!fout){
cerr<ByeBye();
}
intnow=0;
for(inti=1;i<=maxpasslen;i++)


GetPass(len,i,now,fout);
fout.close();
cout<}

voidGetPass(intstrlen,intpasslen,intnow,ofstream&fout){
if(now==passlen){
for(inti=0;ifout<return;
}
for(intj=0;jpass[now]=chars[j];
GetPass(strlen,passlen,now+1,fout);
}
}

voidAdvanced(){
cout<<<"Pleaseselectoneofthefollows:"<<<"1.Addprefixtoeachpasswordinthedictionary"<<<"2.Addsuffixtoeachpasswordinthedictionary"<<<"3.Joindictionariestogether"<<<"4.Filteraspecifieddictionary"<<<"5.Exit"<<<"Pleaseenteryourchoice(1to5):";
charchoice;
do{
cin>>choice;
switch(choice){
case'1':
AddPrefix();
break;
case'2':
AddSuffix();
break;
case'3':
Join();
break;
case'4':
Filter();
case'5':
ByeBye();
default:
cout<<"BadInput!Tryagain:";
}
}while(choice<'1'||choice>'3');
}

voidAddPrefix(){
cout<<<"Makesurethedictionarytobeaddedprefixisincurrentdirectory."<<<"Pleaseenterthenameofthedictionary:";
chardicname[MaxFileNameLen];
cin>>dicname;
ifstreamfin(dicname);
if(!fin){
cerr<ByeBye();
}

cout<charprefix[MaxPassLen];
getchar();
gets(prefix);

ofstreamfout("PreAdded.dic");
if(!fout){
cerr<ByeBye();
}

charbuffer[MaxPassLen],PreAdded[MaxPassLen];
strcpy(PreAdded,prefix);
while(!fin.eof()&fin.good()){
fin.getline(buffer,sizeof(buffer));
if(strlen(buffer)!=0){
strcat(PreAdded,buffer);
fout<strcpy(PreAdded,prefix);
}
}

fin.close();
fout.close();
cout<}

voidAddSuffix(){
cout<<<"Makesurethedictionarytobeaddedsuffixisincurrentdirectory."<<<"Pleaseenterthenameofthedictionary:";
chardicname[MaxFileNameLen];
cin>>dicname;
ifstreamfin(dicname);
if(!fin){
cerr<ByeBye();
}

cout<charsuffix[MaxPassLen];
getchar();
gets(suffix);

ofstreamfout("SufAdded.dic");
if(!fout){
cerr<ByeBye();
}

charbuffer[MaxPassLen];
while(!fin.eof()&fin.good()){
fin.getline(buffer,sizeof(buffer));
if(strlen(buffer)!=0){
strcat(buffer,suffix);
fout<}
}

fin.close();
fout.close();
cout<}

voidJoin(){
cout<<<"Makesurethedictionariestobejoinedarei

ncurrentdirectory."<<<"Pleaseenternamesofdictionaries:";
charcmdline[MaxFileNameLen*MaxFileNum];
getchar();
gets(cmdline);
charfiles[MaxFileNameLen][MaxFileNum];
intlen=strlen(cmdline);
intname=0;
inttmp;
for(inti=0;itmp=0;
while(cmdline[i]!=''&cmdline[i]!='\t'&iif(cmdline[i]==''||cmdline[i]=='\t'){
files[name][tmp]='\0';
while(cmdline[i+1]==''||cmdline[i+1]=='\t')i++;
name++;
}
}
files[name][tmp]='\0';

ofstreamfout("Joined.dic");
charbuffer[MaxPassLen];
for(intj=0;j<=name;j++){
ifstreamfin(files[j]);
if(!fin){
cerr<<<"Erroropeninginputfile:"<ByeBye();
}
while(!fin.eof()&fin.good()){
fin.getline(buffer,sizeof(buffer));
fout<}
fin.close();
}
fout.close();
cout<}

voidFilter(){
cout<<<"Makesurethedictionarytobefilteredisincurrentdirectory."<<<"Pleaseenterthenameofthedictionary:";
chardicname[MaxFileNameLen];
cin>>dicname;

ifstreamfin(dicname);
if(!fin){
cerr<ByeBye();
}
ofstreamfout("Filtered.dic");
if(!fout){
cerr<ByeBye();
}

charbuffer[MaxPassLen];
chartmp[MaxPassLen];
boolisin;
while(!fin.eof()&fin.good()){
fin.getline(buffer,sizeof(buffer));
ifstreamfcmp("Filtered.dic");
if(!fcmp){
cerr<ByeBye();
}
isin=false;
while(!fcmp.eof()&fcmp.good()){
fcmp.getline(tmp,sizeof(tmp));
if(!strcmp(tmp,buffer)){
isin=true;
break;
}
}
if(!isin)fout<fcmp.close();
}

fin.close();
fout.close();
cout<}

voidByeBye(){
cout<<<"Thanksforusingthisprogram."<<<"Ifanybugisfound,pleasecontactme."<<<"Pressentertoexit.";
getchar();
getchar();
exit(0);
}顶部 chris7 发布于:2005-08-2322:27 [1楼]
生Ri电话手机等
根据偶的设想是放在自定义里面的
把涉及的字符作为自定义字符输入
可以包括空格
不需要先筛选
程序有自动过滤重复字符的功能

附件放上来了*g*
附件:7dic.rar(77K)下载次数:50顶部 sgl 发布于:2005-08-2409:33 [2楼]
当设置0-9之间的密码时,只是让输入最大的密码长度,最小的没有指定,都是从长度为1开始的,如果我不想从1开始的话,怎么办呢?

to:斑竹

为什么我回复的消息怎么被删了呢??


--Administrators--
因为本版面是不准非技术回复的且VIP不受此限制那么

一般VIP的非技术回复在丧失作用后可以删除
您让楼主上传压缩附件他已经上传因此您的回复已经没有存在的必要了当然您并没有违反规则是是顺手看见觉得影响不大就删了:)
采取紧缩管理模式并非是要针对什么用户而是尽量让VIP做出表率这样斑竹禁言违反规则的普通会员的时候也可以顺理成章
谢谢垂询顶部 chris7 发布于:2005-08-2502:40 [3楼]
这个是偶考虑的疏忽了
谢谢你的建议
下次发布的时候会改进

你也可以自己修改代码
程序结构还是比较清晰的
容易修改顶部 itcoco05 发布于:2005-09-2208:21 [4楼]
通过调试了,但是真的,挺慢的,不过,作为学习,还是不错的啦,哈哈(c)Copyleft2003-2007,EvilOctalSecurityTeam.
ThisfileisdecompiledbyanunregisteredversionofChmDecompiler.
Regsiteredversiondoesnotshowthismessage.
YoucandownloadChmDecompilerat:https://www.360docs.net/doc/4112755676.html,/


相关文档
最新文档