gpt4 book ai didi

c - 将二进制文件的内容读取为 unsigned long,更新并保存在另一个二进制文件中

转载 作者:行者123 更新时间:2023-11-30 17:31:20 26 4
gpt4 key购买 nike

我想读取一个二进制文件,操作64位加密逻辑并将返回的文件保存在二进制文件中。由于加密对 2 个 4 字节整数 block 进行操作,因此我读取了该文件两次并转换为 long int。但是当我尝试使用相同的过程解密时,我发现从加密输出中保存的内容是错误的。到目前为止,这是我的代码。

     while (fread(buffer, 1, 4, src) == 4) {
//convert char to long
message_left = buffer[3] | (unsigned long) (buffer[2] << 8) | (unsigned long) (buffer[1] << 16) | (unsigned long)(buffer[0] << 24);
fread(buffer, 1, 4, src);
//convert char to long
message_right = buffer[3] | (unsigned long) (buffer[2] << 8) | (unsigned long) (buffer[1] << 16) | (unsigned long)(buffer[0] << 24);
//encrypt
Encrypt(ctx,&message_left,&message_right);
//convert back to char and save
buffer[3] = (unsigned char)message_left;
buffer[2] = (unsigned char)(message_left >> 8);
buffer[1] = (unsigned char)(message_left >> 16);
buffer[0] = (unsigned char)(message_left >> 24);
fwrite(buffer,4,1,dest);
buffer[3] = message_rigt;
buffer[2] = (unsigned char)(message_right >> 8);
buffer[1] = (unsigned char)(message_right >> 16);
buffer[0] = (unsigned char)(message_right >> 24);
fwrite(buffer,4,1,dest);
}

最佳答案

这样的东西有用吗?

unsigned long n[2];
while (fread(n, sizeof(n), 1, src) == 1) {
Encrypt(ctx, &n[0], &n[1]);
fwrite(n, sizeof(n), 1, dest);
}

关于c - 将二进制文件的内容读取为 unsigned long,更新并保存在另一个二进制文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24666145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com