【问题描述】电文的加密规则为:小写字母x变为a,y变为b,z变为c,其它字母变换成该字母ASCII码顺序后三位字母,比如a变为d,b变为e。编写程序,对输入的字符串进行加密。
【输入形式】输入英文字符串
【输出形式】两个提示信息和一个编码后的字符串
【样例输入】china
【样例输出】Please input the text:
After being decrypted:fklqd
//加密电文
#include<iostream>
#include <stdio.h>
using namespace std;
int encrypt(char a[]){
int i;
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='x'){
a[i]='a';
}
if(a[i]=='y'){
a[i]='b';
}
if(a[i]=='z'){
a[i]='c';
}
else
a[i]=a[i]+3;
}
return 0;
}
int main()
{
char a[80];
cout<<"Please input the text:"<<endl;
gets(a);
encrypt(a);
cout<<"After being decrypted:"<<a<<endl;
return 0;
}