输入 | 输入说明 |
---|---|
输出 | 输出说明 |
样例输入 | abcdefg BCDEFGH |
样例输出 | BCDEFGH abcdefg |
#include<iostream>
using namespace std;
#include<string>
//字符串加密
void Encrypt (char *aucPassword, char *aucResult)
{
char *str=aucPassword;
while(*str!='\0')
{
if(isalpha(*str))
{
if((*str>='a') && (*str<='z'))
*aucResult=(char)toupper(*str)+1;
else
*aucResult=(char)tolower(*str)-1;
//str++;
}//if
if (isdigit(*str))
*aucResult=*str+1;
if(isspace(*str))
*aucResult=*str;
str++;
aucResult++;
}//while
*aucResult='\0';
}
//字符串解密
void uncrypt (char *aucPassword, char *aucResult)
{
char *str=aucPassword;
while(*str!='\0')
{
if(isalpha(*str))
{
if((*str>='a') && (*str<='z'))
*aucResult=(char)toupper(*str)+1;
else
*aucResult=(char)tolower(*str)-1;
//str++;
}//if
else if (isdigit(*str))
*aucResult=*str-1;
else
//if (isspace(*str))
*aucResult=*str;
str++;
aucResult++;
}//while
*aucResult='\0';
}
int main()
{
char passWord[100];
gets_s(passWord);
char passWord2[100];
gets_s(passWord2);
char result1[100];
char result2[100];
// 加密输出
Encrypt (passWord, result1);
int i=0;
while(result1[i]!='\0')
{ cout<<result1[i];
i++;
}
cout<<endl;
//解密输出
uncrypt (passWord2, result2);
i=0;
while(result2[i]!='\0')
{ cout<<result2[i];
i++;
}
return 0;
}
VS平台的实验结果如图所示,在OJ平台也可顺利通过!为方便OJ平台上直接通过,显示比较直接。其中第一行为需加密的字符串,第二行为需解密的字符串,第三行为加密过得字符串,第四行为解密过得字符串。