Updated to fix errors with not clearing strings during encoding/decoding

This commit is contained in:
2018-05-14 13:46:37 -04:00
parent dc85d6b5bc
commit c8c56ef159
4 changed files with 10 additions and 5 deletions

View File

@@ -14,8 +14,8 @@
//TODO: Might be able to make encoding and decoding faster for longer messages by actually using a grid of alphabets (Caesar Ciphers)
class Autokey : public Vigenere{
protected:
void encodeSet(std::string& key, std::string input); //Special rules for setting the strings for encoding
void decodeSet(std::string& key, std::string input); //Setting the strings for decoding
void encodeSet(std::string key, std::string input); //Special rules for setting the strings for encoding
void decodeSet(std::string key, std::string input); //Setting the strings for decoding
std::string decode(); //Decodes the inputString
public:
Autokey();

View File

@@ -30,7 +30,7 @@ Autokey::~Autokey(){
* @param key The keyword used for the cipher
* @param input The string that you wish to encode
*/
void Autokey::encodeSet(std::string& key, std::string input){
void Autokey::encodeSet(std::string key, std::string input){
//Remove all unneccessary elements from the key
Vigenere::setKeyword(key);
key = Vigenere::getKeyword();
@@ -57,10 +57,11 @@ void Autokey::encodeSet(std::string& key, std::string input){
* @param key The keyword used for the cipher
* @param input The string that you wish to decode
*/
void Autokey::decodeSet(std::string& key, std::string input){
void Autokey::decodeSet(std::string key, std::string input){
//Remove all unneccessary elements from the key
Vigenere::setKeyword(key);
//Remove all unneccessary elements from the input
inputString = "";
Vigenere::setInputString(input);
}
@@ -133,4 +134,4 @@ std::string Autokey::decode(std::string key, std::string input){
setInputString(input);
decodeSet(key, input); //Decoding is a bit different because part of the key is also part of the original message
return Autokey::decode();
}
}

View File

@@ -118,6 +118,7 @@ std::string Caesar::encode(){
* @return The encoded message
*/
std::string Caesar::encode(int shiftAmount, std::string input){
reset();
setShift(shiftAmount);
setInputString(input);
return encode();
@@ -167,6 +168,7 @@ std::string Caesar::decode(){
* @return The decoded message
*/
std::string Caesar::decode(int shiftAmount, std::string input){
reset();
setShift(shiftAmount);
setInputString(input);
return decode();

View File

@@ -123,6 +123,7 @@ std::vector<unsigned int> Vigenere::getOffsets() const{
* @return The encoded message
*/
std::string Vigenere::encode(){
outputString = "";
//Reserve the correct size for the output string to increase speed for longer messages
outputString.reserve(inputString.size());
@@ -167,6 +168,7 @@ std::string Vigenere::encode(std::string key, std::string input){
* @return The decoded message
*/
std::string Vigenere::decode(){
outputString = "";
//Reserve the correct size for the output string to increase speed for longer messages
outputString.reserve(inputString.size());