您的位置:首页 > 其它

加密一个密码

2015-09-16 19:46 274 查看
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main()
{
	int result = 1;
	int i;
	int count = 0;
	char text[128] = { '\0' };
	char password[128] = { '\0' };
	while (1)
	{
		if (result == 1)
		{
			cout << "输入密码" << endl;
			cin >> text;
			count = strlen(text);
			for (int i = 0; i < count; i++)
			{
				password[i] = text[i] + i + 5;
			}
			//password[i] = '\0';//字符串后面的加0
			cout << "加密后的密码" << password << endl;
		}
		else if (result == 2)
		{
			count = strlen(text);
			for (i = 0; i < count; i++)
			{
				text[i] = password[i] - i - 5;//解密码
			}
			/*text[i] = '\0';*/
			cout << "解密后的密码" << endl;
		}
		else if (result == 3)
		{
			break;
		}
		else
		{
			cout << "输入正确的命令符" << endl;
		}
		cout << "输入1:表示原密码加密,输入2表示解密,输入3,表示退出系统" << endl;
		cin >> result;
	}

	system("pause");
	return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: