我写了一个小程序来解密一个OTP加密的文件.这很好用.
但是我意识到在"Solution.jpg"上调用fopen时我忘了保存返回的文件指针.如您所见,我正在写入文件指针f.我想知道为什么这个代码工作.
#include <stdio.h>
#define FILE_SIZE 4202
int main () {
unsigned char key[FILE_SIZE], otpCipher[FILE_SIZE];
FILE *f = fopen("otpkey.bin", "r");
fread(key, sizeof(char), FILE_SIZE, f);
fclose(f);
f = fopen("otpcipher.bin", "r");
fread(otpCipher, sizeof(char), FILE_SIZE, f);
fclose(f);
fopen("Solution.jpg", "w");
for (int j = 0; j < FILE_SIZE; ++j) {
otpCipher[j] = otpCipher[j] ^ key[j];
fputc(otpCipher[j], f);
}
fclose(f);
return 0;
}
Run Code Online (Sandbox Code Playgroud)