Very lost on the caesar cipher I got the substitution cipher working and close to finishing can anyone help me figure out how to get the caesar cipher working? I've spent 3 hours and can't figure out how to finish this program...
#include<iostream>
#include<vector>
#include<set>
#include<string>
using namespace std;
class Substitution {
int key;
string input;
bool encipher;
public:
//constructor
Substitution(string msg, bool enc) :
input(msg), encipher(enc) {}
//the function for encryption/decryption (Substitution algorithm)
string substitution();
};
class Cipher
{
public:
virtual string encode(string) = 0;
virtual string decode(string) = 0;
};
//the function for encryption/decryption (Substitution algorithm)
string Substitution::substitution()
{
do {
cout << "Enter key in 1..25>> ";
cin >> key;
cin.ignore();
//fflush(stdin);
if (key > 25 || key < 1)
cout << "KEY ERROR";
//check KEY: if encryption/decryption is possibly
} while (key > 25 || key < 1);
string output = "";
for (int i = 0; i < input.size(); ++i)
{
if (isalpha(input[i])) //if letter
{
//offset='A' for upper letter, offset='a' for lowel letter
char offset = isupper(input[i]) ? 'A' : 'a';
//find shift for current letter for encryption (key) or for decryption (26 - key)
int shift = encipher ? key : 26 - key;
//the function for encryption/decryption (Substitution algorithm)
// Encryption
int main() {
/*
Encrypt a string entered by the user
Choose between two different encryption methods
Decrypt a string entered by the user
Choose between two different decryptions methods
Decrypt without knowing the encryption method (provide all possible outputs)
*/