gpt4 book ai didi

javascript - c xor 结果与 javascript xor 不同

转载 作者:太空宇宙 更新时间:2023-11-04 08:53:16 28 4
gpt4 key购买 nike

我正在尝试在 c 中进行某种异或文件加密,并在 javascript 中进行解密(使用 this 作为基础,现在我遇到了以下问题:

例如我想在 C 中执行 73^122,结果是 57,但在 javascript 中相同的操作会产生 51 .为什么会发生这种情况,解决它的正确方法是什么?

这是加密函数的一些C代码

void encrypt_data(FILE* input_file, FILE* output_file, char* key)
{
int key_count = 0; //Used to restart key if strlen(key) < strlen(encrypt)
int encrypt_byte;

while( (encrypt_byte = fgetc(input_file)) != EOF) //Loop through each byte of file until EOF
{
//XOR the data and write it to a file
fputc(encrypt_byte ^ key[key_count], output_file);
printf("original %d\n", encrypt_byte); //yields 73
printf("xoring with %d\n", key[key_count]); // yields 122
printf("xored %d\n", encrypt_byte ^ key[key_count]); // yields 57
break; //breaking just for example purpose

//Increment key_count and start over if necessary
key_count++;
if(key_count == strlen(key))
key_count = 0;
}
}

最佳答案

当我运行时:

#include <stdio.h>

int main() {
printf("%d\n", 73^122);
}

我得到:

51

能否请您向我们展示有问题的 C 代码,我们可以向您展示错误。

关于javascript - c xor 结果与 javascript xor 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18762822/

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