mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-06 18:33:58 -05:00
Added new documentation
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//Ciphers/SourceFiles/Autokey.cpp
|
//Ciphers/SourceFiles/Autokey.cpp
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 5-3-18
|
// Created: 5-3-18
|
||||||
//Modified: 5-3-18
|
//Modified: 5-5-18
|
||||||
//This file contains the implementation of the Autokey class
|
//This file contains the implementation of the Autokey class
|
||||||
|
|
||||||
|
|
||||||
@@ -9,7 +9,28 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
void Autokey::encodeSetKeyword(std::string& key, std::string input){
|
/**
|
||||||
|
* @brief Construct a new Autokey object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Autokey::Autokey(){
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroy the Autokey object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Autokey::~Autokey(){
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the strings correctly for encoding
|
||||||
|
*
|
||||||
|
* @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){
|
||||||
//Remove all unneccessary elements from the key
|
//Remove all unneccessary elements from the key
|
||||||
Vigenere::setKeyword(key);
|
Vigenere::setKeyword(key);
|
||||||
key = Vigenere::getKeyword();
|
key = Vigenere::getKeyword();
|
||||||
@@ -18,7 +39,7 @@ void Autokey::encodeSetKeyword(std::string& key, std::string input){
|
|||||||
input = getInputString();
|
input = getInputString();
|
||||||
key.append(input);
|
key.append(input);
|
||||||
|
|
||||||
//This will take a long time if the keyword in long
|
///This will take a long time if the keyword in long
|
||||||
//Remove the last letter in the string until it is the same size as the input
|
//Remove the last letter in the string until it is the same size as the input
|
||||||
while(key.size() > input.size()){
|
while(key.size() > input.size()){
|
||||||
key.erase(key.end() - 1);
|
key.erase(key.end() - 1);
|
||||||
@@ -30,14 +51,24 @@ void Autokey::encodeSetKeyword(std::string& key, std::string input){
|
|||||||
setOffset();
|
setOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Autokey::decodeSetKeyword(std::string& key, std::string input){
|
/**
|
||||||
|
* @brief Sets the strings correctly for decoding
|
||||||
|
*
|
||||||
|
* @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){
|
||||||
//Remove all unneccessary elements from the key
|
//Remove all unneccessary elements from the key
|
||||||
Vigenere::setKeyword(key);
|
Vigenere::setKeyword(key);
|
||||||
key = Vigenere::getKeyword();
|
|
||||||
//Remove all unneccessary elements from the input
|
//Remove all unneccessary elements from the input
|
||||||
Vigenere::setInputString(input);
|
Vigenere::setInputString(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Decodes the message stored in inputString
|
||||||
|
*
|
||||||
|
* @return The decoded string
|
||||||
|
*/
|
||||||
std::string Autokey::decode(){
|
std::string Autokey::decode(){
|
||||||
//This is going to take a long time no matter what
|
//This is going to take a long time no matter what
|
||||||
//You must decode what you can and then add the decoded portion to the key and do it all over again
|
//You must decode what you can and then add the decoded portion to the key and do it all over again
|
||||||
@@ -77,22 +108,29 @@ std::string Autokey::decode(){
|
|||||||
return outputString;
|
return outputString;
|
||||||
}
|
}
|
||||||
|
|
||||||
Autokey::Autokey(){
|
/**
|
||||||
reset();
|
* @brief Encodes a message using the Autokey cipher
|
||||||
}
|
*
|
||||||
|
* @param key The keyword used for the cipher
|
||||||
Autokey::~Autokey(){
|
* @param input The message that needs to be encoded
|
||||||
}
|
* @return The encoded message
|
||||||
|
*/
|
||||||
std::string Autokey::encode(std::string key, std::string input){
|
std::string Autokey::encode(std::string key, std::string input){
|
||||||
reset();;
|
reset();
|
||||||
encodeSetKeyword(key, input);
|
encodeSet(key, input);
|
||||||
return Vigenere::encode();
|
return Vigenere::encode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Decodes a message using the Autokey cipher
|
||||||
|
*
|
||||||
|
* @param key The keyword used for the cipher
|
||||||
|
* @param input The message that needs to be decoded
|
||||||
|
* @return The decoded message
|
||||||
|
*/
|
||||||
std::string Autokey::decode(std::string key, std::string input){
|
std::string Autokey::decode(std::string key, std::string input){
|
||||||
reset();
|
reset();
|
||||||
setInputString(input);
|
setInputString(input);
|
||||||
decodeSetKeyword(key, input); //Decoding is a bit different because part of the key is also part of the original message
|
decodeSet(key, input); //Decoding is a bit different because part of the key is also part of the original message
|
||||||
return Autokey::decode();
|
return Autokey::decode();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user