This function takes in a string as an argument and then enciphers the numbers and should write an enciphered string to a file. eText in the main seems to not be getting anything from the function and I cannot figure out why.
Function Definition:
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;
}
Main Function:
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;
}
Thanks in advance!
In
Encipherer::encipherershould be
Also, in both if blocks:
should become
Is
shiftdefined on some other place? And you seem to have a}before the lastelsethat shouldn’t be there, if the code is copied correctly.