此函数将字符串作为参数,然后对数字进行加密,并将加密的字符串写入文件。主要的 eText 似乎没有从函数中得到任何东西,我不知道为什么。
功能定义:
string Encipherer::encipherer(string plainMessage){
int i = plainMessage.length();
string eMessage;
cout << i << endl;
for(i = 0; i >= plainMessage.length(); i++){
if(plainMessage[i] >= 65 && plainMessage[i] <= 90){
if(plainMessage[i] + shift > 90){
eMessage[i] += plainMessage[i] - 26 + shift;
}
else{
eMessage += plainMessage[i] + shift;
}
}
else if(plainMessage[i] >= 97 && plainMessage[i] <= 122){
if(plainMessage[i] + shift > 122){
eMessage[i] += plainMessage[i] - 26 + shift;
}
else{
eMessage += plainMessage[i] + shift;
}
}
}
else{
eMessage += plainMessage[i];
}
}
return eMessage;
}
主功能:
int main(){
string plainMessage, eText;
string fileName = "inputText.txt";
ofstream outputText;
outputText.open ("outputText.txt");
Encipherer E(5);
plainMessage = E.encipherFromFile(fileName);
eText = E.encipherer(plainMessage);
outputText << eText;
outputText.close();
return 0;
}
提前致谢!