C++ 奇怪的解密输出

C++ 奇怪的解密输出,c++,encryption,C++,Encryption,我只是在尝试加密和解密,并制作了一个函数来加密、解密和写入文件 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 d

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

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
}
void加密(const std::string&r){
std::string new\u r=“加密:\n”;
对于(int i=0;i
写入文件和加密工作正常。它也解密了它,但看看这个奇怪的输出:

我作为输入编写的是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
}
void加密(const std::string&r){
std::字符串new\u r;
对于(int i=0;i
在原始代码中,您正在将
“加密的:[您的加密邮件]”
写入文件,而不仅仅是
“[您的加密邮件]”
。因此,解密步骤将解密“加密:”部分以及原始加密消息。

尝试以下操作:

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
}
void加密(const std::string&r){
std::字符串new\u r;
对于(int i=0;i

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

show wtofd函数。。。此外,您还描述了新的\u r,即字符串“Encrypted:\n”+加密字符串wtofd函数不是问题所在,它只是一个fstream,用于写入文件显示wtofd函数。。。您还描述了新的\u r,即字符串“Encrypted:\n”+加密字符串wtofd函数不是问题所在,它只是一个写入文件的fstream