XOR一个非常大的文件 [英] XOR on a very big file
问题描述
我想XOR一个非常大的文件(〜50 GO)。
I would like to XOR a very big file (~50 Go).
更多precisely,我想用钥匙3847611839异或32字节的纯文本文件的(因为内存不足),每块这样做,并创建(块之后块)一个新的密码文件。
More precisely, I would like to do so by XORing each block of 32 bytes of a plaintext file (because of lack of memory) with the key 3847611839 and create (block after block) a new cipher file.
感谢您的帮助!
推荐答案
这听上去很不错,并没有听起来像一个家庭作业。
This sounded like fun, and doesn't sound like a homework assignment.
我没有一个previously异或加密的文件,试图用,但如果你转换一个前进和后退,也没有差异。
I don't have a previously xor-encrypted file to try with,but if you convert one back and forward, there's no diff.
这是我试过ATLEAST。请享用! :)这XOR的每一个4个字节0xE555E5BF,我presume这就是你想要的。
That I tried atleast. Enjoy! :) This xor's every 4 bytes with 0xE555E5BF, I presume that's what you wanted.
下面是bloxor.c
Here's 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;
}
这篇关于XOR一个非常大的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!