生成 密码 C++

</pre><pre code_snippet_id="619985" snippet_file_name="blog_20150315_2_4545938" name="code" class="cpp">
#include <iostream>
#include <sstream>
#include <fstream>
#include <list>

using namespace std;

void main()
{
	
	unsigned width;//密码位数
	unsigned wdtStart, wdtEnd; //输出密码位数区间
	list<string> element,pswd, temp, pwdAll; //存放密码字符的容器
	list<string>::iterator it, it2, itEle;
	element.clear();
	pswd.clear();
	pwdAll.clear();//存放密码全部

	unsigned j = 0; //纯数字密码
	stringstream ss;
	string s;

	string logFile;// = ".\\pswd.txt";

	cout << "input save file name" <<endl;
	cin >> logFile;	

	ofstream ostr(logFile.c_str());

	cout << logFile <<endl;

	cout << "input password min start" <<endl;
	cin >> wdtStart;	

	cout << wdtStart <<endl;

	cout << "input password max end" <<endl;
	cin >> wdtEnd;	

	cout << wdtEnd <<endl;

	width = wdtEnd;

	//初始化密码基本单元
	bool produce = true;
	while(produce)
	{
		ss.clear();
		ss << j ;
		ss >> s;
		//cout << "s " << s <<endl;
		element.push_back(s);
		j++;
		if (j > 9)
		{
			produce = false;
		}
	}

	
	for (unsigned i = 1; i <= width; i++ )
	{
		cout << "密码位数: " << i << endl;
		temp.clear();
		if (i == 1)
		{
			for (itEle = element.begin(); itEle != element.end(); itEle++)
			{
				string sEle = (*itEle);
				string s = sEle;
				pswd.push_back(s);
				pwdAll.push_back(s);
				if ((wdtStart <= i) && (i <= wdtEnd))
				{
					ostr << s <<endl;
				}				
			}
		}
		else
		{
			for (it = pswd.begin(); it != pswd.end(); it++ )
			{
				string st = (*it);
				cout << "st " << st <<endl;
				for (itEle = element.begin(); itEle != element.end(); itEle++)
				{
					string sEle = (*itEle);
					string s = st + sEle;
					cout << "s after " << s <<endl;
					temp.push_back(s);
					pwdAll.push_back(s);
					if ((wdtStart <= i) && (i <= wdtEnd))
					{
						ostr << s <<endl;
					}
				}
			}
			pswd.clear();
			pswd = temp;
		}
	}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值