问题描述:
将一段明文加密。加密的规则如下:将每个字符的ascii码的值减去24作为每个字符加密后的值,例如'a'的ascii码的值为97,那么加密后就变成了73。"73"就是'a'的密文,例如,字符串"abc",在加密之后变为"737475",最后,整个密文再进行翻转,得到最终的密文"574737"。现在请你编写程序,对一段文字加密。请定义并使用如下函数:
void encrypt(char *plain, char *cipher)
{
//把原文字符串plain加密后存入字符串cipher
}
输入:
输入一串字符串,只包含数字和字母,最长为200.
输出:
输出加密后的字符串。
样例输入:
zero12
样例输出:
625278097789
参考代码:
#include<stdio.h>
#include<string.h>
void encrypt(char *plain, char *cipher)
{
int i;
for(i=0;plain[i]!='\0';i++)
{
cipher[i]=plain[i]-24;
}
cipher[i]='\0';
}
int main()
{
char source[200],destination[200];
int i,len;
gets(source);
len=strlen(source);
encrypt(source,destination);
for(i=len-1;i>=0;i--)
printf("%d%d",destination[i]%10,destination[i]/10);
return 0;
}