做一个简单的短电文加密解密程序。短电文要求最长80个字符,电文允许出现键盘可以键入的任何英文字母。字符加密可以采用替代法,如:a->c,b->d,...,y->a,z->b,即字母变成其后的第2个字母。 提示: 注意字母包括大写字母和小写字母
#include <iostream>
#include<cstring>
using namespace std;
void encrypt(char a[])
{
for(int i=0;i<strlen(a);i++)
{
a[i]=a[i]+2;
if(a[i]>64+26&&a[i]<97) a[i]-=26;
if(a[i]>96+26) a[i]-=26;
}
}
void dencrypt(char a[])
{
for(int i=0;i<strlen(a);i++)
{
a[i]=a[i]-2;
if(a[i]<65) a[i]+=26;
if(a[i]<97&&a[i]>=95) a[i]+=26;
}
}
int main()
{
char input[80];
cin.getline(input,80);
encrypt(input);
cout<<input<<endl;
dencrypt(input);
cout<<input<<endl;
return 0;
}