部分的に暗号化された文字列をファイルに保存しようとしています。私は何時間も立ち往生しており、間違いがどこにあるのか理解できません。関数は次のとおりです。
void cryptData(string & rawTxt, string & path) {
// the rawTxt is OK. Path is too.
int c(0), counta(0);
while( rawTxt[c] != '\0') { // Reading every char from the string.
if(c <= 122) {
// First 123 char won't be crypted.
// Here I do nothing to rawTxt
}
else { // All remaining chars will be crypted
rawTxt[c] = cryptByte(counta, rawTxt[c]); // Replace current char at position c
// by a crypted char.
counta++;
if(counta > 36) // counta used for crypting,
counta = 0;
}
c++;
}
ofstream toDat(path.c_str() ); // Save recrypted .dat file
toDat << rawTxt.c_str(); // HERE the first 123 chars are not copied in my file...
}
// Crypt chars
char cryptByte(int counta, char b) {
string plainEncryptionKey("odBearBecauseHeIsVeryGoodSiuHungIsAGo");
b+= (char) plainEncryptionKey[counta];
return b;
}
最初の 123 文字がファイルに保存されない理由がわかりません。rawTxt 文字列は、プログラムの最初から最後まで同じ長さです。ください私は夢中になります !
編集:申し訳ありませんが、私の文字列 rawTxt は復号化されたファイルの結果であり、BEGINNING に 123 個のランダムな文字が含まれています。したがって、これらのランダムな文字は、復号化アルゴリズムで消去されます。私は、これらの 123 文字をあるべき場所に戻さずに、愚かにも暗号化アルゴリズムを作成しました。私のコードが別の文字列でうまく機能することに気付いたとき、ヒントを得ました。私の悪い。ご協力いただきありがとうございます!