我正在编写一个程序,该程序使用异或对文件进行编码并将加密文本打印到另一个文件中。从技术上讲它是有效的,但是输出包含多个符号而不仅仅是小写字符。我如何告诉程序只打印小写字母,并能够将其解码回来?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *args[]){
FILE *inFile, *outFile, *keyFile;
int key_count = 0;
int encrypt_byte;
char key[1000];
inFile = fopen("input.txt", "r");
outFile = fopen("output.txt", "w");
keyFile = fopen("key.txt", "r");
while((encrypt_byte = fgetc(inFile)) !=EOF)
{
fputc(encrypt_byte ^ key[key_count], outFile); //XORs
key_count++;
if(key_count == strlen(key)) //Reset the counter
key_count = 0;
}
printf("Complete!");
fclose(inFile);
fclose(outFile);
fclose(keyFile);
return(0);
}
这是我得到的输出:
ÕââÐå朶è”ó
我只是希望它只使用小写字母
最佳答案
你不能。您要么对文件的所有数据进行异或,要么不进行异或。异或运算将产生不可打印的字符。
不过,您可以做的是,首先对它进行异或,然后对其进行 base64 编码。
要取回原始文本/数据,请执行相反的操作。
关于c中符号转换为小写字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33719164/