#include<iostream>
#include<string>
using namespace std;
// 简单的加密算法 凯撒密码算法
char * crypo(string massage)
{
char * ciper = new char[massage.size()];
for(int i = 0; i < massage.size(); i++)
{
ciper[i] = massage.at(i) + 3;
}
return ciper;
}
int main()
{
cout << "input a massage"<<endl;
string massage;
getline(cin, massage);
// cout<<"massage is :" << massage<<endl;
cout<<"the ciper is :"<<endl;
char * ciper = crypo(massage);
for(int i = 0; i < massage.size(); i++)
cout<<ciper[i];
cout<<endl;
return 0;
}
输出结果:
PS D:\c_cpp_simulation> .\crypo.exe
input a massage
我是一个大帅哥吗
the ciper is :
颜褪站基扶为魂朋
本文详细介绍了如何使用C++实现简单的凯撒密码加密算法,并通过实例展示了如何加密和解密字符串。重点讲解了加密函数crypo()的工作原理,以及在main函数中输入和输出加密后的消息。
1326

被折叠的 条评论
为什么被折叠?



