我想用PKCS7做填充:
char *test1 = "azertyuiopqsdfgh";
char *test2 = malloc(32*sizeof(char));
memcpy(test2, test1, strlen(test1));
char pad = (char)(32-strlen(test1));
printf("pad = %d\n", pad);
for(int i = strlen(test1) ; i < 32 ; i++) {
test2[i] = pad;
}
for (int i = 0 ; i < 32 ; i++)
printf("%x ", test2[i]);
printf("\n");我得到了:
pad = 16
61 7a 65 72 74 79 75 69 6f 70 71 73 64 66 67 68 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10但我想:
pad = 16
61 7a 65 72 74 79 75 69 6f 70 71 73 64 66 67 68 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16如何修改我的代码?
提前谢谢。
发布于 2013-06-05 16:33:03
使用
printf("%x ", test2[i]);您使用十六进制(%x)进行打印,而使用
printf("pad = %d\n", pad);` you are printing in decimal (%d). 和(十进制) 16 => (十六进制) 10,所以您显示的内容是正确的。
您可能会使用打印来显示16,而不是10,但我不认为这是您正在搜索的。
https://stackoverflow.com/questions/16934954
复制相似问题