C++ Problem with caesar cipher and encryption decryption with spaces

I have a problem with this code I can't encrypt with spaces for the caesar cipher and decrypt back for caesar cipher with spaces. I have it working on substitution cipher but I can't fix it for caesar cipher I don't know what's wrong with the code? Anyone can help me with this i've tried everything that I can possibly and I still can't figure it out.

#include <iostream>
#include <string>
using namespace std;
class EncryptionMachine //class declaration
{
public: //member functions
EncryptionMachine();//constructor to initialize data members
void subEncrypt();//Substitution encrypter
void subDecrypt();//Substitution decrypter
void CaesarEncrypt(); //Caesar decrypter
void CaesarDecrypt();//Caesar decrypter
void BothDecrypt();//decrypts without knowing the encryption method
void setInput(string input);//mutator function

private://data members
string InputString;
char subEncryptionString[50];//stores data for Substitution encrypter
char subDecryptedString[50];//stores data for Substitution decrypter
char CaesarEncryptionString[50];//stores data for Caesar encrypter
char CaesarDecryptedString[50];//stores data for Caesar decrypter
string AlphaString;//plain text alphabet
string SubString;//cypher key
};


//class definitions
EncryptionMachine::EncryptionMachine()//initializes all data members
{
InputString = " ";

for (int i = 0; i < 50; i++)
{
subEncryptionString[i] = 0;
}

for (int i = 0; i < 50; i++)
{

subDecryptedString[i] = 0;
}

for (int i = 0; i < 50; i++)
{

CaesarEncryptionString[i] = 0;
}
for (int i = 0; i < 50; i++)
{

CaesarDecryptedString[i] = 0;
}


AlphaString = "abcdefghijklmnopqrstuvwxyz ";
SubString = "qwertyuiopasdfghjklzxcvbnm ";
}

void EncryptionMachine::CaesarEncrypt()//Caesars encrytion method
{
getline(cin, InputString);
cout << "Encrypted string: " << endl;
int CaesarIndex;
int shift = 3;
int AlphaNumericIndex;
for (unsigned int i = 0; i < InputString.length(); i++)//nested for loop to go through both input string and alphabet
{
for (unsigned int j = 0; j < AlphaString.length(); j++)
{
if (InputString[i] == AlphaString[j])
{
AlphaNumericIndex = j;
CaesarIndex = (AlphaNumericIndex + shift) % 26;//modulus to rotate the alphabet
cout << AlphaString[CaesarIndex];
CaesarEncryptionString[i] = AlphaString[CaesarIndex];//array to save the data
}
}

}
cout << endl;
}
void EncryptionMachine::BothDecrypt()
{

getline(cin, InputString);
cout << "Possible strings: " << endl;
int CaesarIndex;
int shift;
int AlphaNumericIndex;

for (shift = 0; shift < 25; shift++)//nested for loop to go through all possible shifts
{
for (unsigned int i = 0; i < InputString.length(); i++)//nested for loop to go through both input string and alphabet
{
for (unsigned int j = 0; j < AlphaString.length(); j++)
{
if (InputString[i] == AlphaString[j])
{
AlphaNumericIndex = j;
CaesarIndex = (AlphaNumericIndex - shift + 26) % 26;
cout << AlphaString[CaesarIndex];

}
}

}
cout << endl;
}

int Index;
for (unsigned int j = 0; j < InputString.length(); j++)//nested for loop to go through both input string and substring
{
for (unsigned int i = 0; i < SubString.length(); i++)
{
if (InputString[j] == SubString[i])
{
Index = i;
cout << AlphaString[Index];
subDecryptedString[j] = AlphaString[Index];//array to save the data
}

}

}
cout << endl;


}
void EncryptionMachine::CaesarDecrypt()
{
getline(cin, InputString);
cout << "Decrypted string: " << endl;
int CaesarIndex;
int shift = 3;
int AlphaNumericIndex;
for (unsigned int i = 0; i < InputString.length(); i++)//nested for loop to go through both input string and alphabet
{
for (unsigned int j = 0; j < AlphaString.length(); j++)
{
if (InputString[i] == AlphaString[j])
{
AlphaNumericIndex = j;
CaesarIndex = (AlphaNumericIndex - shift) % 26;
cout << AlphaString[CaesarIndex];
}
}

}
cout << endl;
}

void EncryptionMachine::setInput(string input)
{
InputString = input;
}

void EncryptionMachine::subDecrypt()
{
getline(cin, InputString);
cout << "Decrypted string: " << endl;
int Index;
for (unsigned int j = 0; j < InputString.length(); j++)//nested for loop to go through both input string and substring
{
for (unsigned int i = 0; i < SubString.length(); i++)
{
if (InputString[j] == SubString[i])
{
Index = i;
cout << AlphaString[Index];
subDecryptedString[j] = AlphaString[Index];//array to save the data
}

}

}
cout << endl;
}

void EncryptionMachine::subEncrypt()
{
getline(cin, InputString);
cout << "Encrypted string: " << endl;
int Index;
for (unsigned int j = 0; j < InputString.length(); j++)//nested for loop to go through both input string and alphabet
{
for (unsigned int i = 0; i < AlphaString.length(); i++)
{
if (InputString[j] == AlphaString[i])
{
Index = i;
cout << SubString[Index];
subEncryptionString[j] = SubString[Index];//array to save the data
}

}

}
cout << endl;
}
#include <iostream>
#include <string>
#include "encryptionmachine.h"

using namespace std;

int main()
{

string InputString;//string variable for user input

EncryptionMachine encrypt;//declaring an object of type EncryptionMachine

int choice; //integer for switch statement

do //do while loop for menu
{
cout << endl
<< "Choose 1 to encrypt a string using Substitution Cipher Method.\n"
<< "Choose 2 to decrypt a string using Substitution Cipher Method.\n"
<< "Choose 3 to encrypt a string using Caesar Cipher Method.\n"
<< "Choose 4 to decrypt a string using Caesar Cipher Method.\n"
<< "Choose 5 to decrypt a string without knowing encryption method .\n"
<< "Choose 6 to exit this program.\n" << endl;
cout << "Enter your choice and press Enter: ";
cin >> choice;

switch (choice)//switch statement for menu
{
case 1:
cout << "Please enter a string to encrypt: ";
getline(cin, InputString);//gets user input from keybord
encrypt.setInput(InputString);
encrypt.subEncrypt();
break;
case 2:
cout << "Please enter a string to decrypt: ";
getline(cin, InputString);
encrypt.setInput(InputString);
encrypt.subDecrypt();
break;
case 3:
cout << "Please enter a string to encrypt: ";
getline(cin, InputString);
encrypt.setInput(InputString);
encrypt.CaesarEncrypt();
break;
case 4:
cout << "Please enter a string to decrypt: ";
getline(cin, InputString);
encrypt.setInput(InputString);
encrypt.CaesarDecrypt();
break;
case 5:
cout << "Please enter a string to decrypt: ";
getline(cin, InputString);
encrypt.setInput(InputString);
encrypt.BothDecrypt();
break;
case 6:
cout << "End of Program.\n";
break;
default:
cout << "Not a valid choice.\n"
<< "Choose again.\n";
}
} while (choice != 6);


return 0;
}

Read this and apply code tags.
https://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.