pbos ヘルプとそのプログラム (大きなファイルを xor 処理するためにここで公開) のおかげで、いくつかのテストを実行したところ、別の問題があることがわかりました。必要に応じて。
解決策は、利用可能な整数型を増やすライブラリを含めることだと思います...しかし、文字列などの各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;
}
提案をありがとう。
ダグ