gpt4 book ai didi

c++ - 奇怪的解密输出

转载 作者:行者123 更新时间:2023-11-30 01:59:41 26 4
gpt4 key购买 nike

我只是在试验加密和解密,并制作了一个函数来加密、解密并将两者写入文件...

void encrypt(const std::string& r){

std::string new_r = "Encrypted:\n";
for(int i = 0; i < r.length(); i++)
{
new_r += ~r[i];
}

wtofe("/home/programming/Desktop/latin.txt", new_r); // Writes it to a file
decrypt(new_r);
}

void decrypt(const std::string& r){

std::string new_r = "Decrypted:\n";
for(int i = 0; i < r.length(); i++)
{
new_r += ~(r[i]);
}

wtofd("/home/programming/Desktop/latin.txt", new_r); //Writes it to a file
}

写入文件和加密有效。它还解密了它,但看看这个奇怪的输出:

enter image description here

我作为输入写的是 Davlog,如您所见,它已添加到解密的末尾。但为什么?我做错了什么?

最佳答案

试试这个:

void encrypt(const std::string& r){
std::string new_r;
for(int i = 0; i < r.length(); i++)
{
new_r += ~r[i];
}

wtofe("/home/programming/Desktop/latin.txt", new_r); // Writes it to a file
decrypt(new_r);
}

void decrypt(const std::string& r){

std::string new_r;
for(int i = 0; i < r.length(); i++)
{
new_r += ~(r[i]);
}

wtofd("/home/programming/Desktop/latin.txt", new_r); //Writes it to a file
}

在您的原始代码中,您正在将 "Encrypted:[your encrypted msg]" 而不仅仅是 "[your encrypted msg]" 写入您的文件。因此解密步骤将解密“加密:”部分以及原始加密消息。

关于c++ - 奇怪的解密输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15949343/

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