I am getting an error at the bottom of my code when trying to reference my revised subclass, as follows:
default constructor of 'Revisedcipher' cannot be referenced -- it is a deleted function
I'm not entirely sure what that means or how to fix that. Any help with this would be greatly appreciated.
My code:
#include <iostream>
#include <string>
using namespace std;
class SubstitutionCipher {
public:
//Define your key which is a permutation of 26 alphabets
string key;
//Constructor to create an instance which initializes the key with the given permutation
SubstitutionCipher(string k) {
key = k;
}
//function to encode a string
string encode(string data) {
//initialize encoded data
string encodedData = data;
//replace each character in encodedData with the corresponding mapped data in key. We subtract a char with 'A' to get its position
for (int i = 0; i < data.length(); i++) {
encodedData[i] = key.at(data.at(i) - 'A');
}
//return the encoded data
return encodedData;
}
//function to decode a string
string decode(string data) {
//initialize decoded data
string decodedData = data;
//replace each character in decodedData with the corresponding reverse mapped data in key. We add the position with 'A' to get the corresponding char
for (int i = 0; i < data.length(); i++) {
decodedData[i] = key.find(data.at(i)) + 'A';
}
//return the decoded data
return decodedData;
}
};
class Revisedcipher : public SubstitutionCipher
{
public:
void encrypt(string text, int s)
{
string result = "";
// traverse text
for (int i = 0; i < text.length(); i++)
{
// apply transformation to each character
// Encrypt Uppercase letters
if (isupper(text[i]))
result += char(int(text[i] + s - 65) % 26 + 65);
// Encrypt Lowercase letters
else
result += char(int(text[i] + s - 97) % 26 + 97);
}
// Return the resulting string
// return result;
cout << "\n C_Cipher: " << result;
}
};
//main() method to test the implementation
int main() {
SubstitutionCipher cipher("ZYXWVUTSRQPONMLKJIHGFEDCBA");
string data = "HJOIEBSOMN";
string encodedData = cipher.encode(data);
cout << data << " encoded as " << encodedData << endl;
string decodedData = cipher.decode(encodedData);
cout << encodedData << " decoded as " << decodedData;
Revisedcipher cc;
cc.encrypt(data, 4);
}