特定のキーを使用してテキストを復号化するプログラムに取り組んでいます。 replace()
を使用しようとしていますが、動作していないようです。たとえば、qwert
はhello
に復号化されますが、出力はhlllo
です。この場合、qwert
のw
は復号化されてe
になりますが、次にl
に再暗号化されます。特定の文字を行に置き換える、C++
入力:
私はこの問題を解決するにはどうすればよいxnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
should come out as:
the quick brown fox jumps over the lazy dog
I'm getting:
oga yaacd brozn aox gamav ovar oga lazy dog
?
int main()
{
// ...
myFile.open("decrypt.txt");
while (myFile.good())
{
getline(myFile, line2);
// now line2 is, e.g., "xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj"
// help here
for (int i = 0; i < 26; i++)
{
replace(line2.begin(), line2.end(), key[i], fox[i]);
}
v.push_back(line2);
}
myFile.close();
for (int i = 0; i < numline; i++)
{
cout << "line " << i <<" = " << v[i] << endl;
}
return 0;
}
ok私はすべての不要なコードを削除し、少し良く説明しました。 – acrogenesis