哪位大哥帮我把这个程序写写

来源:百度知道 编辑:UC知道 时间:2024/05/30 13:18:21
某个公司采用公用电话传递数据信息,数据是小于8位的整数,为了安全,在传递过程中需要加密,规则如下:

首先将数据倒序,然后将每位数据都加上5。再用和除以10的余数代替该数字,最后将第一位和最后一位数字交换,
要求通过程序实现数据加密的过程,还要可以解密,程序要用C++写。
开头要是这样的
#include<stdio.h>
void main()

#include <stdio.h>
void main()
{
char d[10];
printf("please input the number:\n");
gets(d);
int n;
int strl(const char*);
void en(char*,int);
n=strl(d);
en(d,n);
printf("encode: %s\n",d);
en(d,n);
printf("decode: %s\n",d);
}
void en(char *d,int n)
{
int i;
char tmp;
for(i=0;i<n/2;i++) {
tmp=d[n-i-1];
d[n-i-1]=(d[i]-'0'+5)%10+'0';
d[i]=(tmp-'0'+5)%10+'0';
}
tmp=d[n-1];
d[n-1]=d[0];
d[0]=tmp;
}
int strl(const char *p) {
int i=0;
while(p[i++]!=0);
return i-1;
}

要求写的清楚些,倒序是指位倒序还是字节倒序?

c++没用过,如果是c的话还可以