diff --git a/Cryption.cpp b/Cryption.cpp index 1eb85a8..6512776 100644 --- a/Cryption.cpp +++ b/Cryption.cpp @@ -1,21 +1,18 @@ -#include "Cryption.h" +#include"Cryption.h" Cryption::Cryption() -{ -} +{ } + +Cryption::~Cryption() +{ } + Cryption::Cryption(const std::string& message) -{ - this->message = message; -} +{ this->message = message; } void Cryption::setMessage(const std::string& message) -{ - this->message = message; -} +{ this->message = message; } std::string Cryption::getMessage() const -{ - return message; -} +{ return message; } diff --git a/Cryption.h b/Cryption.h index f47cf7b..08604fb 100644 --- a/Cryption.h +++ b/Cryption.h @@ -1,15 +1,15 @@ #ifndef CRYPTION_H #define CRYPTION_H -#include -#include +#include +#include class Cryption { public: Cryption(); + ~Cryption(); Cryption(const std::string&); - //void setMessage(const std::string&); std::string getMessage() const; protected: diff --git a/Decryption.cpp b/Decryption.cpp index a3e9556..ac9cdfa 100644 --- a/Decryption.cpp +++ b/Decryption.cpp @@ -1,24 +1,24 @@ -#include +#include #include -#include -#include +#include +#include -#include "Decryption.h" -#include "GenerateKeys.h" +#include"Decryption.h" +#include"GenerateKeys.h" Decryption::Decryption() -{ -} +{ } + +Decryption::~Decryption() +{ } + Decryption::Decryption(const std::string& message) -{ - this->message = message; -} +{ this->message = message; } void Decryption::setDecryptedMessage(const std::string& message) -{ - this->decryptedMessage = message; -} +{ this->decryptedMessage = message; } + void Decryption::decryptMessage() { GenerateKeys gk{}; @@ -31,7 +31,7 @@ void Decryption::decryptMessage() ioEvent.close(); - for (auto indexOfChar = 0; indexOfChar> tmpString; return tmpString; } - - -unsigned short getTwoNumberedKey(unsigned short& number) -{ - std::string wholeNumber{std::to_string(number)}; - char hundred[] = {wholeNumber.at(0)}; - char ten[] = {wholeNumber.at(1)}; - char one[] {wholeNumber.at(2)}; - - - unsigned short hundread, tenN, oneN; - hundread = number; -} diff --git a/Decryption.h b/Decryption.h index ecd99ce..40500f9 100644 --- a/Decryption.h +++ b/Decryption.h @@ -1,16 +1,17 @@ #ifndef DECRYPTION_H #define DECRYPTION_H -#include -#include +#include +#include -#include "Cryption.h" +#include"Cryption.h" class Decryption : public Cryption { public: Decryption(); + ~Decryption(); Decryption(const std::string&); void setDecryptedMessage(const std::string&); diff --git a/Encryption.cpp b/Encryption.cpp index bfed4dc..6fd44fb 100644 --- a/Encryption.cpp +++ b/Encryption.cpp @@ -1,30 +1,28 @@ -#include -#include -#include +#include +#include +#include -#include "Encryption.h" -#include "GenerateKeys.h" +#include"Encryption.h" +#include"GenerateKeys.h" Encryption::Encryption() -{ -} +{ } + +Encryption::~Encryption() +{ } + Encryption::Encryption(const std::string& message) -{ - this->message = message; -} +{ this->message = message; } void Encryption::setEncryptedMessage(const std::string& encryptedMessage) -{ - this->encryptedMessage = encryptedMessage; -} +{ this->encryptedMessage = encryptedMessage; } void Encryption::encryptMessage() { - int numberOfNewLines{0}; + auto numberOfNewLines = 0; GenerateKeys gk{}; ioEvent.open("encryptedFile.txt", std::ios::out); - //std::cout << "String to encrypt: " << message << std::endl; for (auto index = 0; index != message.size(); ++index) { char stringIndex = message.at(index); @@ -42,6 +40,4 @@ void Encryption::encryptMessage() std::string Encryption::getEncryptedMessage() const -{ - return encryptedMessage; -} +{ return encryptedMessage; } diff --git a/Encryption.h b/Encryption.h index 684faba..64d739a 100644 --- a/Encryption.h +++ b/Encryption.h @@ -1,15 +1,16 @@ #ifndef ENCRYPTION_H #define ENCRYPTION_H -#include -#include +#include +#include -#include "Cryption.h" +#include"Cryption.h" class Encryption : public Cryption { public: Encryption(); + ~Encryption(); Encryption(const std::string&); void setEncryptedMessage(const std::string&); diff --git a/GenerateKeys.cpp b/GenerateKeys.cpp index 2dfa7e9..b1281d8 100644 --- a/GenerateKeys.cpp +++ b/GenerateKeys.cpp @@ -1,9 +1,9 @@ -#include +#include #include #include #include -#include "GenerateKeys.h" +#include"GenerateKeys.h" GenerateKeys::GenerateKeys() { @@ -11,23 +11,25 @@ GenerateKeys::GenerateKeys() populateNumbers(); populateLetters(); - for (auto index = 0; index!=symbols.size(); ++index) + for (auto index = 0u; index!=symbols.size(); ++index) allCharacters.push_back(symbols[index]); - for (auto index = 0; index!=numbers.size(); ++index) + for (auto index = 0u; index!=numbers.size(); ++index) allCharacters.push_back(numbers[index]); - for (auto index = 0; index!=letters.size(); ++index) + for (auto index = 0u; index!=letters.size(); ++index) allCharacters.push_back(letters[index]); populateDecryptedValues(); populateEncryptedValues(); } +GenerateKeys::~GenerateKeys() +{ } void GenerateKeys::populateDecryptedValues() { std::fstream readKeys{}; - readKeys.open("default_keys.txt", std::ios::in); + readKeys.open(defaultKeyFileName, std::ios::in); std::string tmpKey{}; - for (auto index = 0; index!=allCharacters.size(); ++index) + for (auto index = 0u; index!=allCharacters.size(); ++index) { readKeys >> tmpKey; decryptedCharacters[tmpKey] = static_cast(allCharacters[index]); @@ -40,9 +42,9 @@ void GenerateKeys::populateDecryptedValues() void GenerateKeys::populateEncryptedValues() { std::fstream readKeys{}; - readKeys.open("default_keys.txt", std::ios::in); + readKeys.open(defaultKeyFileName, std::ios::in); std::string tmpKey{}; - for (auto index = 0; index!=allCharacters.size(); ++index) + for (auto index = 0u; index!=allCharacters.size(); ++index) { readKeys >> tmpKey; encryptedCharacters[decryptedCharacters[tmpKey]] = tmpKey; @@ -99,21 +101,26 @@ void GenerateKeys::generateKey(std::string& key, const int& SIZE) } void GenerateKeys::keyMove() { - std::string tmpKey{}; for (auto index = 0; index!=totalCharacters; ++index) { + std::string tmpKey{}; generateKey(tmpKey, keySize); keys.push_back(tmpKey); - tmpKey = ""; } + if (isThereRepetition()) + { + keys.clear(); + keyMove(); + } + std::cout << "No repetitions in keys" << std::endl; } void GenerateKeys::print(const std::vector& ch) { - for (auto index = 0; index!=ch.size(); ++index) + for (auto index = 0u; index!=ch.size(); ++index) std::cout << ch[index] << " "; std::cout << std::endl; } -void GenerateKeys::checkRepetition() +bool GenerateKeys::isThereRepetition() { for (auto index = 0; index!=totalCharacters; ++index) { @@ -125,14 +132,18 @@ void GenerateKeys::checkRepetition() ++repetition; } if (repetition > 1) + { std::cout << "Too much repetitive stuff" << std::endl; + return true; + } } + return false; } void GenerateKeys::keyDump() { std::fstream dump{}; - dump.open("default_keys.txt", std::ios::out); - for (auto index = 0; index!=keys.size(); ++index) + dump.open(defaultKeyFileName, std::ios::out); + for (auto index = 0u; index!=keys.size(); ++index) dump << keys[index] << '\n'; dump.close(); } diff --git a/GenerateKeys.h b/GenerateKeys.h index 2056403..eb531f9 100644 --- a/GenerateKeys.h +++ b/GenerateKeys.h @@ -8,9 +8,8 @@ class GenerateKeys { public: - typedef unsigned short unsignedShort; - GenerateKeys(); + ~GenerateKeys(); void populateDecryptedValues(); void populateEncryptedValues(); @@ -29,20 +28,21 @@ private: void addRange(std::vector&, int, const int); void generateKey(std::string&, const int&); - void checkRepetition(); + bool isThereRepetition(); void print(const std::vector&); char getChar(std::vector&); std::vector keys{}; - std::vector symbols{}; - std::vector numbers{}; - std::vector letters{}; - std::vector allCharacters{}; + std::vector symbols; + std::vector numbers; + std::vector letters; + std::vector allCharacters; std::map encryptedCharacters{}; std::map decryptedCharacters{}; + std::string defaultKeyFileName{"default_keys.txt"}; //KeySize show equal the value in key const int keySize{5}; const int totalCharacters{63}; diff --git a/KeyManagementWindow.cpp b/KeyManagementWindow.cpp index f6f6ff4..83c6e16 100644 --- a/KeyManagementWindow.cpp +++ b/KeyManagementWindow.cpp @@ -1,31 +1,36 @@ -#include "KeyManagementWindow.h" -#include "GenerateKeys.h" +#include"KeyManagementWindow.h" +#include"GenerateKeys.h" -#include -#include -#include -#include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent) { - GenerateKeys gk; + GenerateKeys gk{}; - comboBoxOfKeys = new QComboBox; - valueOfKey = new QLineEdit; + comboBoxOfKeys = new QComboBox{}; + valueOfKey = new QLineEdit{}; + generateNewDefaultKeys = new QPushButton(tr("Generate New Default Key")); - QVBoxLayout* vBox = new QVBoxLayout; - QHBoxLayout* hBox = new QHBoxLayout; + vBox = new QVBoxLayout; + hBox = new QHBoxLayout; + QHBoxLayout* hBox2 = new QHBoxLayout; setContentsOfComboBox(); hBox->addWidget(comboBoxOfKeys); hBox->addWidget(valueOfKey); + hBox2->addWidget(generateNewDefaultKeys); + vBox->addLayout(hBox); + vBox->addLayout(hBox2); setLayout(vBox); @@ -35,6 +40,15 @@ KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent) setWindowTitle("Key Management Window"); QObject::connect(comboBoxOfKeys, SIGNAL(currentIndexChanged(int)), SLOT(test())); + QObject::connect(generateNewDefaultKeys, SIGNAL(clicked()), this, SLOT(generation())); +} +KeyManagementWindow::~KeyManagementWindow() +{ + delete comboBoxOfKeys; + delete valueOfKey; + delete generateNewDefaultKeys; + delete hBox; + delete vBox; } @@ -42,8 +56,7 @@ void KeyManagementWindow::setContentsOfComboBox() { GenerateKeys gk; - std::cout << "got here" << std::endl; - for (auto index = 0; index!=gk.allCharacters.size(); ++index) + for (auto index = 0u; index!=gk.allCharacters.size(); ++index) { std::string ch{static_cast(gk.allCharacters[index])}; QString bl = QString::fromStdString(ch); @@ -52,17 +65,22 @@ void KeyManagementWindow::setContentsOfComboBox() } void KeyManagementWindow::test() { - GenerateKeys gk; - QString bo = comboBoxOfKeys->currentText(); - std::string k = bo.toStdString(); - char f; + GenerateKeys gk{}; + QString bo{comboBoxOfKeys->currentText()}; + std::string k{bo.toStdString()}; + char f{}; std::stringstream lazy{}; lazy << k; lazy >> f; - //std::cout << "character: " << f << std::endl; std::string value{gk.encryptedCharacters[f]}; - QString v = QString::fromStdString(value); + QString v{QString::fromStdString(value)}; valueOfKey->setText(v); } +void KeyManagementWindow::generation() +{ + GenerateKeys gk{}; + gk.keyMove(); + gk.keyDump(); +} diff --git a/KeyManagementWindow.h b/KeyManagementWindow.h index d1f8da4..63ae329 100644 --- a/KeyManagementWindow.h +++ b/KeyManagementWindow.h @@ -1,25 +1,35 @@ #ifndef KEYMANAGEMENTWINDOW_H #define KEYMANAGEMENTWINDOW_H -#include -#include -#include +#include +#include +#include +#include +#include +class QHBoxLayout; +class QVBoxLayout; class QComboBox; class QLineEdit; +class QPushButton; class KeyManagementWindow : public QDialog { Q_OBJECT public: KeyManagementWindow(QWidget* parent = 0); + ~KeyManagementWindow(); void setContentsOfComboBox(); private slots: void test(); + void generation(); private: - QComboBox* comboBoxOfKeys; - QLineEdit* valueOfKey; + QHBoxLayout* hBox{}; + QVBoxLayout* vBox{}; + QComboBox* comboBoxOfKeys{}; + QLineEdit* valueOfKey{}; + QPushButton* generateNewDefaultKeys; }; #endif diff --git a/Main.cpp b/Main.cpp index e058d8c..fcafda2 100644 --- a/Main.cpp +++ b/Main.cpp @@ -1,6 +1,6 @@ -#include +#include -#include "MessagingControls.h" +#include"MessagingControls.h" int main(int argc, char* argv[]) { diff --git a/MessagingControls.cpp b/MessagingControls.cpp index 0ade2bc..f95a348 100644 --- a/MessagingControls.cpp +++ b/MessagingControls.cpp @@ -1,11 +1,11 @@ -#include -#include -#include -#include +#include +#include +#include +#include -#include "MessagingControls.h" -#include "KeyManagementWindow.h" -#include "Encryption.h" +#include"MessagingControls.h" +#include"KeyManagementWindow.h" +#include"Encryption.h" #include"Decryption.h" MessagingControls::MessagingControls() diff --git a/MessagingControls.h b/MessagingControls.h index 3524d3a..ee81d51 100644 --- a/MessagingControls.h +++ b/MessagingControls.h @@ -1,18 +1,18 @@ #ifndef MESSAGINGCONTROLS_H #define MESSAGINGCONTROLS_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include class QLabel;