加密一个密码
#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';//字符串后面的加0cout << "加密后的密碼" << 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;}
總結