c语言改错,急啊!!!!!!!!!!!!
小宇初学C语言,老师给他布置了作业,要求他按照字符所在的位置和固定的位移来在字母表中循环移动字母,来实现一个简单的加密算法,可是他写了段程序,却始终达不到想要的结果,你能...
小宇初学C语言,老师给他布置了作业,要求他按照字符所在的位置和固定的位移来在字母表中循环移动字母,来实现一个简单的加密算法,可是他写了段程序,却始终达不到想要的结果,你能帮他修正一下程序中的错误么
#include "stdlib.h"
//--------------------------Do Not Modify Start---------------------
unsigned short hash(char* InStr){
unsigned int len;
unsigned short Crc16Table[256];
unsigned int i,j;
unsigned short Crc;
for (i = 0; i < 256; i++){
Crc = i;
for (j = 0; j < 8; j++){
if(Crc & 0x1)
Crc = (Crc >> 1) ^ 0xA001;
else
Crc >>= 1;
}
Crc16Table[i] = Crc;
}
Crc=0x0000;
len = 23;
for(i=0; i<len; i++){
Crc = (Crc >> 8) ^ Crc16Table[(Crc & 0xFF) ^ InStr[i]];
}
//Crc ^= 0x0000;
return Crc;
}
int check(char *pKey) {
if(hash(pKey) == 0x248e)
return 1;
else
return 0;
}
char kkk[]="odskrwheoilxzjweorukjfc";
#define MOVE 20
//--------------------------Do Not Modify End---------------------
void main() {
char c;
int i,j;
for(i=0;i<sizeof(kkk);i++) {
c = kkk[i];
j = c - 'a';
j = (j+i-MOVE) % 26;
kkk[i] = 'a' + j;
}
//--------------------------Do Not Modify Start---------------------
if (check(kkk))
printf("KEY{%s}",kkk);
else
printf("ERROR");
//--------------------------Do Not Modify End---------------------
} 展开
#include "stdlib.h"
//--------------------------Do Not Modify Start---------------------
unsigned short hash(char* InStr){
unsigned int len;
unsigned short Crc16Table[256];
unsigned int i,j;
unsigned short Crc;
for (i = 0; i < 256; i++){
Crc = i;
for (j = 0; j < 8; j++){
if(Crc & 0x1)
Crc = (Crc >> 1) ^ 0xA001;
else
Crc >>= 1;
}
Crc16Table[i] = Crc;
}
Crc=0x0000;
len = 23;
for(i=0; i<len; i++){
Crc = (Crc >> 8) ^ Crc16Table[(Crc & 0xFF) ^ InStr[i]];
}
//Crc ^= 0x0000;
return Crc;
}
int check(char *pKey) {
if(hash(pKey) == 0x248e)
return 1;
else
return 0;
}
char kkk[]="odskrwheoilxzjweorukjfc";
#define MOVE 20
//--------------------------Do Not Modify End---------------------
void main() {
char c;
int i,j;
for(i=0;i<sizeof(kkk);i++) {
c = kkk[i];
j = c - 'a';
j = (j+i-MOVE) % 26;
kkk[i] = 'a' + j;
}
//--------------------------Do Not Modify Start---------------------
if (check(kkk))
printf("KEY{%s}",kkk);
else
printf("ERROR");
//--------------------------Do Not Modify End---------------------
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询