mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-06 18:33:58 -05:00
Added propper error handling
This commit is contained in:
@@ -88,6 +88,10 @@ void Vigenere::setKeyword(std::string key){
|
||||
//Make sure offset is empty before adding to it
|
||||
offset.clear();
|
||||
setOffset();
|
||||
//If after all the eliminating of unusable characters the keyword is empty throw an error
|
||||
if(keyword == ""){
|
||||
throw emptyKeyword();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,11 +161,13 @@ std::string Vigenere::encode(){
|
||||
*/
|
||||
std::string Vigenere::encode(std::string key, std::string input){
|
||||
reset();
|
||||
setKeyword(key);
|
||||
//Throw an error if there is no keyword
|
||||
//Would be better to throw an error here
|
||||
if(keyword == ""){
|
||||
return "Error! Empty keyword\n";
|
||||
try{
|
||||
setKeyword(key);
|
||||
}
|
||||
//Catch the emptyKeyword error if it was thrown
|
||||
catch(emptyKeyword){
|
||||
std::string errorString = "After all unusable characters were stripped away the keyword given was empty";
|
||||
return errorString;
|
||||
}
|
||||
setInputString(input);
|
||||
return encode();
|
||||
@@ -200,11 +206,13 @@ std::string Vigenere::decode(){
|
||||
*/
|
||||
std::string Vigenere::decode(std::string key, std::string input){
|
||||
reset();
|
||||
setKeyword(key);
|
||||
//Throw an error if there is no keyword
|
||||
//Would be better to throw an error here
|
||||
if(keyword == ""){
|
||||
return "Error! Empty keyword\n";
|
||||
try{
|
||||
setKeyword(key);
|
||||
}
|
||||
//Catch the emptyKeyword error if it was thrown
|
||||
catch(emptyKeyword){
|
||||
std::string errorString = "After all unusable characters were stripped away the keyword given was empty";
|
||||
return errorString;
|
||||
}
|
||||
setInputString(input);
|
||||
return decode();
|
||||
|
||||
Reference in New Issue
Block a user