【发布时间】:2013-04-11 12:55:18
【问题描述】:
我只是在尝试加密和解密,并制作了一个函数来加密、解密和写入文件......
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
}
写入文件并加密有效。它也解密了它,但看看这个奇怪的输出:
我作为输入写的是 Davlog,正如您所见,它已添加到解密的末尾。但为什么?我做错了什么?
【问题讨论】:
-
显示 wtofd 函数...你也在描述 new_r,它是字符串 "Encrypted:\n" + 加密字符串
-
wtofd 函数不是问题,它只是一个写入文件的 fstream
标签: c++ encryption