我想异或一个非常大的文件(~50 Go)。
更准确地说,我想通过使用 key 3847611839 对明文文件的每个 32 字节 block (由于内存不足)进行异或运算并创建(一个接一个地 block )一个新的密码文件。
感谢您的帮助!!
最佳答案
这听起来很有趣,而且不像家庭作业。
我没有以前异或加密的文件可以尝试,但如果你来回转换一个文件,就没有差异。
我至少试过了。享受! :) 这个 xor 每 4 个字节与 0xE555E5BF,我想这就是你想要的。
这里是 bloxor.c
// bloxor.c - by Peter Boström 2009, public domain, use as you see fit. :)
#include <stdio.h>
unsigned int xormask = 0xE555E5BF; //3847611839 in hex.
int main(int argc, char *argv[])
{
printf("%x\n", xormask);
if(argc < 3)
{
printf("usage: bloxor 'file' 'outfile'\n");
return -1;
}
FILE *in = fopen(argv[1], "rb");
if(in == NULL)
{
printf("Cannot open: %s", argv[2]);
return -1;
}
FILE *out = fopen(argv[2], "wb");
if(out == NULL)
{
fclose(in);
printf("unable to open '%s' for writing.",argv[2]);
return -1;
}
char buffer[1024]; //presuming 1024 is a good block size, I dunno...
int count;
while(count = fread(buffer, 1, 1024, in))
{
int i;
int end = count/4;
if(count % 4)
++end;
for(i = 0;i < end; ++i)
{
((unsigned int *)buffer)[i] ^= xormask;
}
if(fwrite(buffer, 1, count, out) != count)
{
fclose(in);
fclose(out);
printf("cannot write, disk full?\n");
return -1;
}
}
fclose(in);
fclose(out);
return 0;
}
关于c - 对一个非常大的文件进行 XOR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1656961/