密码生成器
简单的小破密码生成器 qwq
也不知道搞了这个有啥用处
目前还比较脆弱,不支持不合法输入
反正就是个瞎搞的东西 qwq
代码:
/*
Name: 密码生成器1.0
Author: q779
Date: 2021.5.20
Function:
{
可以生成长度4-256的密码
允许包含数字、大小写字母以及部分特殊字符
可以用于制作密码字典
}
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <random>
using namespace std;
#define num_start 0
#define num_end 9
#define Upper_start 10
#define Upper_end 35
#define Lower_start 36
#define Lower_end 61
#define Sp_char_start 62
#define Sp_char_end 69
#define min_len 4
#define max_len 256
string pwdch="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*";
void check_pwd(int &start,int &end,bool num,bool Upper,bool Lower,bool Sp_char)
{
if(!(num||Upper||Lower||Sp_char))
{
cout << "输入不合法!" << endl;
return ;
}
if(num) start=num_start;
else if(Upper) start=Upper_start;
else if(Lower) start=Lower_start;
else start=Sp_char_start;
if(Sp_char) end=Sp_char_end;
else if(Lower) end=Lower_end;
else if(Upper) end=Upper_end;
else end=num_end;
}
void make_pwd(bool num,bool Upper,bool Lower,bool Sp_char,int len)
{
if(len>max_len||len<min_len)
{
cout << "不合法的输入" << endl;
return;
}
int start,end;
check_pwd(start,end,num,Upper,Lower,Sp_char);
int idx;
string res;
for(int i=1; i<=len; i++)
{
do
idx=rand()%(end-start+1)+start;
while
(!(
num && num_start <= idx && idx <= num_end ||
Upper && Upper_start <= idx && idx <= Upper_end ||
Lower && Lower_start <= idx && idx <=Lower_end ||
Sp_char && Sp_char_start <=idx && idx <=Sp_char_end
));
res+=pwdch[idx];
}
cout << res << endl;
}
signed main()
{
srand((unsigned)time(NULL));
ios::sync_with_stdio(0);
bool num,Upper,Lower,Sp_char;
int len,times;
cout << "欢迎使用密码生成器1.0" << endl;
cout << "请输入生成密码的限制条件" << endl;
cout << "是否包含数字? [0/1] > "; cin >> num;
cout << "是否包含大写字母? [0/1] > "; cin >> Upper;
cout << "是否包含小写字母? [0/1] > "; cin >> Lower;
cout << "是否包含特殊字符? [0/1] > "; cin >> Sp_char;
cout << "生成的长度? [4-256] > "; cin >> len;
cout << "生成数量? [0/1] > "; cin >> times;
#define LOCAL
#ifdef LOCAL
freopen("pwdmaker.txt","w",stdout);
#endif
for(int i=1; i<=times; i++)
make_pwd(num,Upper,Lower,Sp_char,len);
#ifdef LOCAL
fclose(stdout);
// system("cp pwdmaker.txt /home/qry");//复制到主目录下
// 这里的路径可以自行修改
#endif
return 0;
}