mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-06 18:33:58 -05:00
Added tests for Autokey
This commit is contained in:
37
testMain.hpp
37
testMain.hpp
@@ -11,6 +11,7 @@
|
|||||||
#include "Headers/Vigenere.hpp"
|
#include "Headers/Vigenere.hpp"
|
||||||
#include "Headers/Atbash.hpp"
|
#include "Headers/Atbash.hpp"
|
||||||
#include "Headers/Morse.hpp"
|
#include "Headers/Morse.hpp"
|
||||||
|
#include "Headers/Autokey.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
#define VIGENERE_TEST
|
#define VIGENERE_TEST
|
||||||
#define ATBASH_TEST
|
#define ATBASH_TEST
|
||||||
#define MORSE_TEST
|
#define MORSE_TEST
|
||||||
|
#define AUTOKEY_TEST
|
||||||
enum codingState { ENCODE, DECODE };
|
enum codingState { ENCODE, DECODE };
|
||||||
std::string testingError(codingState type, const std::string& input, const std::string& output, const std::string& cipher);
|
std::string testingError(codingState type, const std::string& input, const std::string& output, const std::string& cipher);
|
||||||
#endif //TEST_VERSION definition
|
#endif //TEST_VERSION definition
|
||||||
@@ -47,6 +49,10 @@ bool atbashTest(std::string& errorString);
|
|||||||
bool morseTest(std::string& errorString);
|
bool morseTest(std::string& errorString);
|
||||||
#endif //MORSE_TEST
|
#endif //MORSE_TEST
|
||||||
|
|
||||||
|
#ifdef AUTOKEY_TEST
|
||||||
|
bool autokeyTest(std::string& errorString);
|
||||||
|
#endif //AUTOKEY_TEST
|
||||||
|
|
||||||
|
|
||||||
#ifdef TEST_VERSION
|
#ifdef TEST_VERSION
|
||||||
|
|
||||||
@@ -403,4 +409,35 @@ bool morseTest(std::string& errorString){
|
|||||||
}
|
}
|
||||||
#endif //MORSE_TEST
|
#endif //MORSE_TEST
|
||||||
|
|
||||||
|
#ifdef AUTOKEY_TEST
|
||||||
|
bool autokeyTest(std::string& errorString){
|
||||||
|
bool passed = true;
|
||||||
|
std::string keyword, inputString, outputString, cipherString;
|
||||||
|
Autokey cipher;
|
||||||
|
|
||||||
|
//Test from wikipedia
|
||||||
|
keyword = "QUEENLY";
|
||||||
|
inputString = "Attack at dawn";
|
||||||
|
outputString = "QNXEPVYTWTWP";
|
||||||
|
//Setup the cipher
|
||||||
|
cipherString = cipher.encode(keyword, inputString);
|
||||||
|
//If the cipher didn't spit out the correct string throw an error
|
||||||
|
if(cipherString != outputString){
|
||||||
|
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||||
|
passed = false;
|
||||||
|
}
|
||||||
|
//This removes the spaces and turns everything capital so the reverse will work correctly
|
||||||
|
inputString = cipher.getInputString();
|
||||||
|
|
||||||
|
//Do the same thing in reverse
|
||||||
|
cipher.reset();
|
||||||
|
cipherString = cipher.decode(keyword, outputString);
|
||||||
|
//If the cipher didn't spit out the correct string throw an error
|
||||||
|
if(cipherString != inputString){
|
||||||
|
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||||
|
passed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //AUTOKEY_TEST
|
||||||
|
|
||||||
#endif //TEST_VERSION
|
#endif //TEST_VERSION
|
||||||
|
|||||||
Reference in New Issue
Block a user