无符号字符到char*和C中的int?

Fms*_*rat 3 c int char visual-studio-2010 unsigned-char

处理一些需要在函数中使用unsigned char的加密,但希望在解密后转换为char以供使用.所以我有:

unsigned char plaintext[16];
char *plainchar;
int plainint;

... Code now populates plaintext with data that happens to all be plain text
Run Code Online (Sandbox Code Playgroud)

现在在这一点上,让我们说明文实际上是一个"0123456789"的数据字符串.如何将明文的值作为"012456789"获取为plainchar,同时将plainint作为123456789?

- 编辑 -

当明文等于"AAAAAAAAAA105450"时执行此操作:

unsigned char plaintext[16];
char *plainchar;
int plainint;

... Code now populates plaintext with data that happens to all be plain text

plainchar = (char*)plaintext;
Run Code Online (Sandbox Code Playgroud)

使plainchar等于"AAAAAAAAAA105450╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠┤∙7",sizeof = 51.加密代码是rijndael示例代码,所以它应该工作正常.

谢谢,本

Som*_*ude 5

您的纯文本字符串未终止.所有字符串都必须有一个额外的字符,告诉字符串的结尾.这个角色是'\0'.

plaintext变量声明为

unsigned char plaintext[17];
Run Code Online (Sandbox Code Playgroud)

完成解密后添加此项

plaintext[last_pos] = '\0';
Run Code Online (Sandbox Code Playgroud)

切换last_pos到解密文本的最后位置,默认为16(数组的最后一个索引).