感谢 pbos 帮助及其程序(在此处发布,用于 xoring 一个大文件),我执行了一些测试,发现我还有另一个问题:将掩码更改为另一个 128 位的掩码后,没有默认类型那么大如所须。
我认为一个解决方案可以是包含一个库来增加可用的整数类型......但我更喜欢解释每个 128 位值,例如字符串。在不损失性能的情况下这可能吗?
这是当前程序(带有错误“整数常量对于它的类型来说太大”):
#include <stdio.h>
#include <stdlib.h>
#define BLOCKSIZE 128
#define MASK 0xA37c54f173f02889a64be02f2bc44112 /* a 128 bits constant */
void
usage(const char *cmd)
{
fprintf(stderr, "Usage: %s <in-file> [<out-file>]\n", cmd);
exit (EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
if (argc < 3) usage(argv[0]);
FILE *in = fopen(argv[1], "rb");
if (in == NULL)
{
printf("Cannot open: %s", argv[2]);
return EXIT_FAILURE;
}
FILE *out = fopen(argv[2], "wb");
if (out == NULL)
{
fclose(in);
printf("Unable to open '%s' for writing.", argv[2]);
}
char buffer[BLOCKSIZE];
int count;
while (count = fread(buffer, 1, BLOCKSIZE, in))
{
int i;
for (i = 0; i < count; i++)
{
((unsigned long *)buffer)[i] ^= MASK; /* this line is bugged */
}
if (fwrite(buffer, 1, count, out) != count)
{
fclose(in);
fclose(out);
printf("Cannot write, disk full?\n");
return EXIT_FAILURE;
}
}
fclose(in);
fclose(out);
return EXIT_SUCCESS;
}
感谢您的任何建议。
道格