大虾们帮忙啊~~求一C++小程序,急急!!

来源:百度知道 编辑:UC知道 时间:2024/06/11 10:28:54
使用替换加密(恺撒加密法)编程。
加密规则是:将原来的小写字母用字母表中其后面的第3个字母的大写形式来替换,大写字母按同样的规则用小写字母替换。对于字母表中最后的3个字母,可将字母表看成是首末衔接的。例如字母c就用F来替换,字母y用B替换。试将字符串“I Love China”译成密码。

//时间紧,没仔细顾及效率,多多包涵了,如果想提高效率,可以稍微改下
#include<iostream>
#include<string>
using namespace std;
void encrypt(string &s)//加密
{

int i=s.length();
for(int j=0;j<i;++j)
{
if('A'<=s[j]&&s[j]<='Z')
{
if('A'<=s[j]&&s[j]<='W')
s[j]+=3;
else
s[j]-=23;
//cout<<s[j];
s[j]+=32;
//cout<<s[j]<<endl;
}
else if('a'<=s[j]&&s[j]<='z')
{
if('a'<=s[j]&&s[j]<='w')
s[j]+=3;
else
s[j]-=23;
//cout<<s[j];
s[j]-=32;
//cout<<s[j]<<endl;

}

}
}
void decrypt(string&s)//解密
{
int i=s.length();
for(int j=0;j<i;++j)
{
if('A'<=s[j]&&s[j]<='Z')
{
if('D'<=s[j]&&s[j]<