我正在尝试实现(AES 加密的)移位行功能,我编写了以下函数,但是对于对应于位置 2,3 3,2 和 3,3 的数组元素没有正确交换。请看看并建议...
预期输出 http://en.wikipedia.org/wiki/File:AES-ShiftRows.svg
void shiftRow(unsigned char **state){
int i,j,n; unsigned char *temp;
temp =(unsigned char *)malloc(sizeof(unsigned char));
for(i=1;i<4;i++){
*temp =state[i][0];
printf("\t%x",*temp);
for(j=0;j<4;j++){
n = ((i+j)>3?(i+j)-4:i+j);
state[i][j]=state[i][n];
}
printf("\t%x\n",*temp);
state[i][j-i]=*temp;
}
}
最佳答案
我不得不做一些解决方法,不是完美的解决方案,但完成了工作...
void shiftRow(unsigned char **state){
int i,j,n; unsigned char temp;
// temp =(unsigned char *)malloc(sizeof(unsigned char));
for(i=1;i<2;i++){
temp =state[i][0];
//printf("\t%x",temp);
for(j=0;j<4;j++){
n = ((i+j)>3?(i+j)-4:i+j);
state[i][j]=state[i][n];
}
printf("\t%x\n",temp);
state[i][j-i]=temp;
}
temp =state[2][0];
state[2][0]=state[2][2];
state[2][2]=temp;
temp =state[2][1];
state[2][1]=state[2][3];
state[2][3]=temp;
temp =state[3][0];
state[3][0]=state[3][3];
state[3][3]=state[3][2];
state[3][2]=state[3][1];
state[3][1]=temp;
} //shiftrow ends
任何其他解决方案/方法将不胜感激
关于c - 在 C 中为 AES 中的移位行移位数组元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22462704/