我正在編寫一個程序,它使用xor編碼文件並將加密的文本打印到另一個文件中。它在技術上是有效的,但是輸出包含幾個符號而不是隻有小寫字符。我如何告訴程序只打印小寫字母,並能夠解碼回來?將符號轉換爲小寫字母c
#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);
}
這裏是輸出我得到:
ÕââÐå朶è」ó
我只是希望它僅使用小寫字母
你問的是如何異或大寫或小寫?請閱讀XOR操作和字符集編碼。 – Olaf
嘗試向我們展示您的代碼,並明確指定您期望的輸出以及您實際獲得的內容。 – bznein