Refractoring code and adding memory management
This commit is contained in:
@@ -1,11 +1,5 @@
|
|||||||
#include"Cryption.h"
|
#include"Cryption.h"
|
||||||
|
|
||||||
Cryption::Cryption()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Cryption::~Cryption()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Cryption::Cryption(const std::string& message)
|
Cryption::Cryption(const std::string& message)
|
||||||
{ this->message = message; }
|
{ this->message = message; }
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -1,22 +1,20 @@
|
|||||||
#ifndef CRYPTION_H
|
#ifndef CRYPTION_H
|
||||||
#define CRYPTION_H
|
#define CRYPTION_H
|
||||||
|
|
||||||
#include<fstream>
|
|
||||||
#include<string>
|
#include<string>
|
||||||
|
|
||||||
class Cryption
|
class Cryption
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Cryption();
|
Cryption() = default;
|
||||||
~Cryption();
|
~Cryption() = default;
|
||||||
Cryption(const std::string&);
|
Cryption(const std::string&);
|
||||||
|
|
||||||
std::string getMessage() const;
|
std::string getMessage() const;
|
||||||
protected:
|
protected:
|
||||||
void setMessage(const std::string&);
|
void setMessage(const std::string&);
|
||||||
|
|
||||||
std::string message{};
|
std::string message;
|
||||||
std::fstream ioEvent{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+6
-10
@@ -1,4 +1,5 @@
|
|||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
#include<fstream>
|
||||||
#include<sstream>
|
#include<sstream>
|
||||||
#include<ios>
|
#include<ios>
|
||||||
#include<string>
|
#include<string>
|
||||||
@@ -6,14 +7,11 @@
|
|||||||
#include"Decryption.h"
|
#include"Decryption.h"
|
||||||
#include"GenerateKeys.h"
|
#include"GenerateKeys.h"
|
||||||
|
|
||||||
Decryption::Decryption()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Decryption::~Decryption()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Decryption::Decryption(const std::string& message)
|
Decryption::Decryption(const std::string& message)
|
||||||
{ this->message = message; }
|
{
|
||||||
|
this->message = message;
|
||||||
|
decryptMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Decryption::setDecryptedMessage(const std::string& message)
|
void Decryption::setDecryptedMessage(const std::string& message)
|
||||||
@@ -22,7 +20,7 @@ void Decryption::setDecryptedMessage(const std::string& message)
|
|||||||
void Decryption::decryptMessage()
|
void Decryption::decryptMessage()
|
||||||
{
|
{
|
||||||
GenerateKeys gk{};
|
GenerateKeys gk{};
|
||||||
|
std::fstream ioEvent{};
|
||||||
ioEvent.open("encryptedFile.txt", std::ios::in);
|
ioEvent.open("encryptedFile.txt", std::ios::in);
|
||||||
|
|
||||||
std::string messageToBeDecrypted{}, decryptedMessage{};
|
std::string messageToBeDecrypted{}, decryptedMessage{};
|
||||||
@@ -35,10 +33,8 @@ void Decryption::decryptMessage()
|
|||||||
{
|
{
|
||||||
char cryptedKey[5]{};
|
char cryptedKey[5]{};
|
||||||
for (auto index = 0; index!=5; ++index)
|
for (auto index = 0; index!=5; ++index)
|
||||||
{
|
|
||||||
cryptedKey[index] = (messageToBeDecrypted.at(indexOfChar + index));
|
cryptedKey[index] = (messageToBeDecrypted.at(indexOfChar + index));
|
||||||
|
|
||||||
}
|
|
||||||
decryptedMessage += gk.decryptedCharacters[cstringToString(cryptedKey, 5)];
|
decryptedMessage += gk.decryptedCharacters[cstringToString(cryptedKey, 5)];
|
||||||
}
|
}
|
||||||
setDecryptedMessage(decryptedMessage);
|
setDecryptedMessage(decryptedMessage);
|
||||||
|
|||||||
+3
-4
@@ -9,9 +9,8 @@
|
|||||||
class Decryption : public Cryption
|
class Decryption : public Cryption
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Decryption() = default;
|
||||||
Decryption();
|
~Decryption() = default;
|
||||||
~Decryption();
|
|
||||||
Decryption(const std::string&);
|
Decryption(const std::string&);
|
||||||
|
|
||||||
void setDecryptedMessage(const std::string&);
|
void setDecryptedMessage(const std::string&);
|
||||||
@@ -21,7 +20,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string cstringToString(char[], const int&);
|
std::string cstringToString(char[], const int&);
|
||||||
std::string decryptedMessage{};
|
std::string decryptedMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-16
@@ -1,40 +1,32 @@
|
|||||||
#include<ios>
|
#include<ios>
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
#include<fstream>
|
||||||
#include<string>
|
#include<string>
|
||||||
|
|
||||||
#include"Encryption.h"
|
#include"Encryption.h"
|
||||||
#include"GenerateKeys.h"
|
#include"GenerateKeys.h"
|
||||||
|
|
||||||
Encryption::Encryption()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Encryption::~Encryption()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Encryption::Encryption(const std::string& message)
|
Encryption::Encryption(const std::string& message)
|
||||||
{ this->message = message; }
|
{
|
||||||
|
this->message = message;
|
||||||
|
encryptMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Encryption::setEncryptedMessage(const std::string& encryptedMessage)
|
void Encryption::setEncryptedMessage(const std::string& encryptedMessage)
|
||||||
{ this->encryptedMessage = encryptedMessage; }
|
{ this->encryptedMessage = encryptedMessage; }
|
||||||
void Encryption::encryptMessage()
|
void Encryption::encryptMessage()
|
||||||
{
|
{
|
||||||
auto numberOfNewLines = 0;
|
|
||||||
GenerateKeys gk{};
|
GenerateKeys gk{};
|
||||||
|
std::fstream ioEvent{};
|
||||||
ioEvent.open("encryptedFile.txt", std::ios::out);
|
ioEvent.open("encryptedFile.txt", std::ios::out);
|
||||||
|
|
||||||
for (auto index = 0; index != message.size(); ++index)
|
for (auto indexOfString = 0u; indexOfString!=message.size(); ++indexOfString)
|
||||||
{
|
|
||||||
char stringIndex = message.at(index);
|
|
||||||
if (stringIndex == '\n')
|
|
||||||
++numberOfNewLines;
|
|
||||||
}
|
|
||||||
for (auto indexOfString = 0; indexOfString!=message.size(); ++indexOfString)
|
|
||||||
{
|
{
|
||||||
ioEvent << gk.encryptedCharacters[message.at(indexOfString)];
|
ioEvent << gk.encryptedCharacters[message.at(indexOfString)];
|
||||||
encryptedMessage += (gk.encryptedCharacters[message.at(indexOfString)]);
|
encryptedMessage += (gk.encryptedCharacters[message.at(indexOfString)]);
|
||||||
}
|
}
|
||||||
setEncryptedMessage(encryptedMessage);
|
this->encryptedMessage = encryptedMessage;
|
||||||
ioEvent.close();
|
ioEvent.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -9,17 +9,16 @@
|
|||||||
class Encryption : public Cryption
|
class Encryption : public Cryption
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Encryption();
|
Encryption() = default;
|
||||||
~Encryption();
|
~Encryption() = default;
|
||||||
Encryption(const std::string&);
|
Encryption(const std::string&);
|
||||||
|
|
||||||
void setEncryptedMessage(const std::string&);
|
void setEncryptedMessage(const std::string&);
|
||||||
void encryptMessage();
|
void encryptMessage();
|
||||||
|
|
||||||
std::string getEncryptedMessage() const;
|
std::string getEncryptedMessage() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string encryptedMessage{};
|
std::string encryptedMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+11
-15
@@ -11,18 +11,13 @@ GenerateKeys::GenerateKeys()
|
|||||||
populateNumbers();
|
populateNumbers();
|
||||||
populateLetters();
|
populateLetters();
|
||||||
|
|
||||||
for (auto index = 0u; index!=symbols.size(); ++index)
|
addToCentralContainer(symbols);
|
||||||
allCharacters.push_back(symbols[index]);
|
addToCentralContainer(numbers);
|
||||||
for (auto index = 0u; index!=numbers.size(); ++index)
|
addToCentralContainer(letters);
|
||||||
allCharacters.push_back(numbers[index]);
|
|
||||||
for (auto index = 0u; index!=letters.size(); ++index)
|
|
||||||
allCharacters.push_back(letters[index]);
|
|
||||||
|
|
||||||
populateDecryptedValues();
|
populateDecryptedValues();
|
||||||
populateEncryptedValues();
|
populateEncryptedValues();
|
||||||
}
|
}
|
||||||
GenerateKeys::~GenerateKeys()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void GenerateKeys::populateDecryptedValues()
|
void GenerateKeys::populateDecryptedValues()
|
||||||
{
|
{
|
||||||
@@ -33,7 +28,7 @@ void GenerateKeys::populateDecryptedValues()
|
|||||||
{
|
{
|
||||||
readKeys >> tmpKey;
|
readKeys >> tmpKey;
|
||||||
decryptedCharacters[tmpKey] = static_cast<char>(allCharacters[index]);
|
decryptedCharacters[tmpKey] = static_cast<char>(allCharacters[index]);
|
||||||
tmpKey = "";
|
tmpKey.assign("");
|
||||||
}
|
}
|
||||||
readKeys.close();
|
readKeys.close();
|
||||||
decryptedCharacters["#2a9u"] = (char) 32;
|
decryptedCharacters["#2a9u"] = (char) 32;
|
||||||
@@ -48,7 +43,7 @@ void GenerateKeys::populateEncryptedValues()
|
|||||||
{
|
{
|
||||||
readKeys >> tmpKey;
|
readKeys >> tmpKey;
|
||||||
encryptedCharacters[decryptedCharacters[tmpKey]] = tmpKey;
|
encryptedCharacters[decryptedCharacters[tmpKey]] = tmpKey;
|
||||||
tmpKey = "";
|
tmpKey.assign("");
|
||||||
}
|
}
|
||||||
readKeys.close();
|
readKeys.close();
|
||||||
encryptedCharacters[(char) 32] = "#2a9u";
|
encryptedCharacters[(char) 32] = "#2a9u";
|
||||||
@@ -70,16 +65,19 @@ void GenerateKeys::populateNumbers()
|
|||||||
}
|
}
|
||||||
void GenerateKeys::populateLetters()
|
void GenerateKeys::populateLetters()
|
||||||
{
|
{
|
||||||
|
addRange(letters, 65, 90);
|
||||||
addRange(letters, 97, 122);
|
addRange(letters, 97, 122);
|
||||||
}
|
}
|
||||||
void GenerateKeys::addRange(std::vector<int>& ch, int from, const int to)
|
void GenerateKeys::addRange(std::vector<int>& ch, int from, const int to)
|
||||||
{
|
{
|
||||||
auto range = to - from;
|
auto range = to - from;
|
||||||
for (auto index = 0; index<=range; ++index)
|
for (auto index = 0; index<=range; ++index, ++from)
|
||||||
{
|
|
||||||
ch.push_back(from);
|
ch.push_back(from);
|
||||||
++from;
|
|
||||||
}
|
}
|
||||||
|
void GenerateKeys::addToCentralContainer(std::vector<int>& con)
|
||||||
|
{
|
||||||
|
for (auto index = 0u; index!=con.size(); ++index)
|
||||||
|
allCharacters.push_back(con[index]);
|
||||||
}
|
}
|
||||||
void GenerateKeys::generateKey(std::string& key, const int& SIZE)
|
void GenerateKeys::generateKey(std::string& key, const int& SIZE)
|
||||||
{
|
{
|
||||||
@@ -127,10 +125,8 @@ bool GenerateKeys::isThereRepetition()
|
|||||||
std::string chosenOne{keys[index]};
|
std::string chosenOne{keys[index]};
|
||||||
auto repetition{0};
|
auto repetition{0};
|
||||||
for (auto innerIndex = 0; innerIndex!=totalCharacters; ++innerIndex)
|
for (auto innerIndex = 0; innerIndex!=totalCharacters; ++innerIndex)
|
||||||
{
|
|
||||||
if (chosenOne == keys[innerIndex])
|
if (chosenOne == keys[innerIndex])
|
||||||
++repetition;
|
++repetition;
|
||||||
}
|
|
||||||
if (repetition > 1)
|
if (repetition > 1)
|
||||||
{
|
{
|
||||||
std::cout << "Too much repetitive stuff" << std::endl;
|
std::cout << "Too much repetitive stuff" << std::endl;
|
||||||
|
|||||||
+2
-1
@@ -9,7 +9,7 @@ class GenerateKeys
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GenerateKeys();
|
GenerateKeys();
|
||||||
~GenerateKeys();
|
~GenerateKeys() = default;
|
||||||
|
|
||||||
void populateDecryptedValues();
|
void populateDecryptedValues();
|
||||||
void populateEncryptedValues();
|
void populateEncryptedValues();
|
||||||
@@ -26,6 +26,7 @@ private:
|
|||||||
void populateNumbers();
|
void populateNumbers();
|
||||||
void populateLetters();
|
void populateLetters();
|
||||||
void addRange(std::vector<int>&, int, const int);
|
void addRange(std::vector<int>&, int, const int);
|
||||||
|
void addToCentralContainer(std::vector<int>&);
|
||||||
|
|
||||||
void generateKey(std::string&, const int&);
|
void generateKey(std::string&, const int&);
|
||||||
bool isThereRepetition();
|
bool isThereRepetition();
|
||||||
|
|||||||
+19
-27
@@ -15,40 +15,32 @@ KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent)
|
|||||||
{
|
{
|
||||||
GenerateKeys gk{};
|
GenerateKeys gk{};
|
||||||
|
|
||||||
comboBoxOfKeys = new QComboBox{};
|
comboBoxOfKeys = unique_ptr<QComboBox>{new QComboBox{}};
|
||||||
valueOfKey = new QLineEdit{};
|
valueOfKey = unique_ptr<QLineEdit>{new QLineEdit{}};
|
||||||
generateNewDefaultKeys = new QPushButton(tr("Generate New Default Key"));
|
generateNewDefaultKeys = unique_ptr<QPushButton>{new QPushButton(tr("Generate New Default Key"))};
|
||||||
|
|
||||||
vBox = new QVBoxLayout;
|
vBox = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
hBox = new QHBoxLayout;
|
hBox = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
||||||
QHBoxLayout* hBox2 = new QHBoxLayout;
|
hBox2 = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
||||||
|
|
||||||
setContentsOfComboBox();
|
setContentsOfComboBox();
|
||||||
hBox->addWidget(comboBoxOfKeys);
|
hBox.get()->addWidget(comboBoxOfKeys.get());
|
||||||
hBox->addWidget(valueOfKey);
|
hBox.get()->addWidget(valueOfKey.get());
|
||||||
|
|
||||||
hBox2->addWidget(generateNewDefaultKeys);
|
hBox2.get()->addWidget(generateNewDefaultKeys.get());
|
||||||
|
|
||||||
vBox->addLayout(hBox);
|
vBox.get()->addLayout(hBox.get());
|
||||||
vBox->addLayout(hBox2);
|
vBox.get()->addLayout(hBox2.get());
|
||||||
|
|
||||||
setLayout(vBox);
|
setLayout(vBox.get());
|
||||||
|
|
||||||
setFixedWidth(400);
|
setFixedWidth(windowWidth);
|
||||||
setFixedHeight(400);
|
setFixedHeight(windowHeight);
|
||||||
|
|
||||||
setWindowTitle("Key Management Window");
|
setWindowTitle("Key Management Window");
|
||||||
|
|
||||||
QObject::connect(comboBoxOfKeys, SIGNAL(currentIndexChanged(int)), SLOT(test()));
|
QObject::connect(comboBoxOfKeys.get(), SIGNAL(currentIndexChanged(int)), SLOT(test()));
|
||||||
QObject::connect(generateNewDefaultKeys, SIGNAL(clicked()), this, SLOT(generation()));
|
QObject::connect(generateNewDefaultKeys.get(), SIGNAL(clicked()), this, SLOT(generation()));
|
||||||
}
|
|
||||||
KeyManagementWindow::~KeyManagementWindow()
|
|
||||||
{
|
|
||||||
delete comboBoxOfKeys;
|
|
||||||
delete valueOfKey;
|
|
||||||
delete generateNewDefaultKeys;
|
|
||||||
delete hBox;
|
|
||||||
delete vBox;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,13 +52,13 @@ void KeyManagementWindow::setContentsOfComboBox()
|
|||||||
{
|
{
|
||||||
std::string ch{static_cast<char>(gk.allCharacters[index])};
|
std::string ch{static_cast<char>(gk.allCharacters[index])};
|
||||||
QString bl = QString::fromStdString(ch);
|
QString bl = QString::fromStdString(ch);
|
||||||
comboBoxOfKeys->addItem(bl);
|
comboBoxOfKeys.get()->addItem(bl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void KeyManagementWindow::test()
|
void KeyManagementWindow::test()
|
||||||
{
|
{
|
||||||
GenerateKeys gk{};
|
GenerateKeys gk{};
|
||||||
QString bo{comboBoxOfKeys->currentText()};
|
QString bo{comboBoxOfKeys.get()->currentText()};
|
||||||
std::string k{bo.toStdString()};
|
std::string k{bo.toStdString()};
|
||||||
char f{};
|
char f{};
|
||||||
|
|
||||||
@@ -76,7 +68,7 @@ void KeyManagementWindow::test()
|
|||||||
|
|
||||||
std::string value{gk.encryptedCharacters[f]};
|
std::string value{gk.encryptedCharacters[f]};
|
||||||
QString v{QString::fromStdString(value)};
|
QString v{QString::fromStdString(value)};
|
||||||
valueOfKey->setText(v);
|
valueOfKey.get()->setText(v);
|
||||||
}
|
}
|
||||||
void KeyManagementWindow::generation()
|
void KeyManagementWindow::generation()
|
||||||
{
|
{
|
||||||
|
|||||||
+13
-6
@@ -6,6 +6,8 @@
|
|||||||
#include<QHBoxLayout>
|
#include<QHBoxLayout>
|
||||||
#include<QComboBox>
|
#include<QComboBox>
|
||||||
#include<QLineEdit>
|
#include<QLineEdit>
|
||||||
|
#include<QPushButton>
|
||||||
|
#include<memory>
|
||||||
|
|
||||||
class QHBoxLayout;
|
class QHBoxLayout;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
@@ -13,23 +15,28 @@ class QComboBox;
|
|||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
||||||
|
using std::unique_ptr;
|
||||||
|
|
||||||
class KeyManagementWindow : public QDialog
|
class KeyManagementWindow : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
KeyManagementWindow(QWidget* parent = 0);
|
KeyManagementWindow(QWidget* parent = 0);
|
||||||
~KeyManagementWindow();
|
~KeyManagementWindow() = default;
|
||||||
|
|
||||||
void setContentsOfComboBox();
|
void setContentsOfComboBox();
|
||||||
private slots:
|
private slots:
|
||||||
void test();
|
void test();
|
||||||
void generation();
|
void generation();
|
||||||
private:
|
private:
|
||||||
QHBoxLayout* hBox{};
|
unique_ptr<QHBoxLayout> hBox;
|
||||||
QVBoxLayout* vBox{};
|
unique_ptr<QHBoxLayout> hBox2;
|
||||||
QComboBox* comboBoxOfKeys{};
|
unique_ptr<QVBoxLayout> vBox;
|
||||||
QLineEdit* valueOfKey{};
|
unique_ptr<QComboBox> comboBoxOfKeys;
|
||||||
QPushButton* generateNewDefaultKeys;
|
unique_ptr<QLineEdit> valueOfKey;
|
||||||
|
unique_ptr<QPushButton> generateNewDefaultKeys;
|
||||||
|
int windowWidth{400};
|
||||||
|
int windowHeight{400};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+44
-63
@@ -2,7 +2,7 @@
|
|||||||
#include<QString>
|
#include<QString>
|
||||||
#include<QIcon>
|
#include<QIcon>
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
#include<memory>
|
||||||
#include"MessagingControls.h"
|
#include"MessagingControls.h"
|
||||||
#include"KeyManagementWindow.h"
|
#include"KeyManagementWindow.h"
|
||||||
#include"Encryption.h"
|
#include"Encryption.h"
|
||||||
@@ -10,47 +10,40 @@
|
|||||||
|
|
||||||
MessagingControls::MessagingControls()
|
MessagingControls::MessagingControls()
|
||||||
{
|
{
|
||||||
textForCryption = new QTextEdit;
|
|
||||||
cryptionChoice = true;
|
|
||||||
|
|
||||||
setupMainWindow();
|
setupMainWindow();
|
||||||
}
|
}
|
||||||
MessagingControls::~MessagingControls()
|
|
||||||
{
|
|
||||||
delete lblOfEncryptedBox;
|
|
||||||
delete cryptionButon;
|
|
||||||
delete textForCryption;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MessagingControls::setupMainWindow()
|
void MessagingControls::setupMainWindow()
|
||||||
{
|
{
|
||||||
cryptionButon = new QPushButton(tr("XO"));
|
textForCryption = unique_ptr<QTextEdit>{new QTextEdit{}};
|
||||||
cryptionSwitch = new QPushButton(tr("encrypt chosen"));
|
cryptionButon = unique_ptr<QPushButton>{new QPushButton(tr("XO"))};
|
||||||
|
cryptionSwitch = unique_ptr<QPushButton>{new QPushButton(tr("encrypt chosen"))};
|
||||||
|
|
||||||
buttonLayout = new QVBoxLayout;
|
buttonLayout = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
buttonWidget = new QWidget;
|
buttonWidget = unique_ptr<QWidget>{new QWidget};
|
||||||
buttonDockWidget = new QDockWidget;
|
buttonDockWidget = unique_ptr<QDockWidget>{new QDockWidget};
|
||||||
buttonDockWidget->setWindowTitle(tr("Cryption Controls"));
|
buttonDockWidget.get()->setWindowTitle(tr("Cryption Controls"));
|
||||||
buttonLayout->addWidget(cryptionButon);
|
buttonLayout.get()->addWidget(cryptionButon.get());
|
||||||
buttonLayout->addWidget(cryptionSwitch);
|
buttonLayout.get()->addWidget(cryptionSwitch.get());
|
||||||
buttonWidget->setLayout(buttonLayout);
|
buttonWidget.get()->setLayout(buttonLayout.get());
|
||||||
buttonDockWidget->setWidget(buttonWidget);
|
buttonDockWidget.get()->setWidget(buttonWidget.get());
|
||||||
buttonDockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
buttonDockWidget.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||||
setCentralWidget(buttonDockWidget);
|
setCentralWidget(buttonDockWidget.get());
|
||||||
|
|
||||||
QDockWidget* cryptionArea = new QDockWidget(tr("Cryption"));
|
cryptionArea = unique_ptr<QDockWidget>{new QDockWidget(tr("Cryption"))};
|
||||||
cryptionArea->setWidget(textForCryption);
|
cryptionArea.get()->setWidget(textForCryption.get());
|
||||||
cryptionArea->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
cryptionArea.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||||
addDockWidget(Qt::LeftDockWidgetArea, cryptionArea);
|
addDockWidget(Qt::LeftDockWidgetArea, cryptionArea.get());
|
||||||
|
|
||||||
|
addDockWidget(Qt::LeftDockWidgetArea, cryptionArea.get());
|
||||||
|
|
||||||
createMenus();
|
createMenus();
|
||||||
|
|
||||||
QObject::connect(closeApplication, SIGNAL(triggered()), this, SLOT(close()));
|
QObject::connect(closeApplication.get(), SIGNAL(triggered()), this, SLOT(close()));
|
||||||
QObject::connect(cryptionSwitch, SIGNAL(clicked()), this, SLOT(changeCryptionType()));
|
QObject::connect(cryptionSwitch.get(), SIGNAL(clicked()), this, SLOT(changeCryptionType()));
|
||||||
QObject::connect(cryptionButon, SIGNAL(clicked()), this, SLOT(determineCryption()));
|
QObject::connect(cryptionButon.get(), SIGNAL(clicked()), this, SLOT(determineCryption()));
|
||||||
QObject::connect(keyEdit, SIGNAL(triggered()), this, SLOT(keyManagementWindow()));
|
QObject::connect(keyEdit.get(), SIGNAL(triggered()), this, SLOT(keyManagementWindow()));
|
||||||
|
|
||||||
setWindowTitle("Encryption Decryption Messaging");
|
setWindowTitle("Encryption Decryption Messaging");
|
||||||
setFixedHeight(mainWindowHeight);
|
setFixedHeight(mainWindowHeight);
|
||||||
@@ -58,70 +51,58 @@ void MessagingControls::setupMainWindow()
|
|||||||
}
|
}
|
||||||
void MessagingControls::createMenus()
|
void MessagingControls::createMenus()
|
||||||
{
|
{
|
||||||
fileMenu = menuBar()->addMenu(tr("File"));
|
fileMenu = unique_ptr<QMenu>{menuBar()->addMenu(tr("File"))};
|
||||||
editMenu = menuBar()->addMenu(tr("Edit"));
|
editMenu = unique_ptr<QMenu>{menuBar()->addMenu(tr("Edit"))};
|
||||||
|
|
||||||
closeApplication = new QAction(new QObject(nullptr));
|
closeApplication = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||||
closeApplication->setText("Exit Application");
|
closeApplication.get()->setText("Exit Application");
|
||||||
|
|
||||||
keyEdit = new QAction(new QObject(nullptr));
|
keyEdit = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||||
keyEdit->setText("Key Management");
|
keyEdit.get()->setText("Key Management");
|
||||||
|
|
||||||
fileMenu->addAction(closeApplication);
|
fileMenu.get()->addAction(closeApplication.get());
|
||||||
|
editMenu.get()->addAction(keyEdit.get());
|
||||||
editMenu->addAction(keyEdit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MessagingControls::changeCryptionType()
|
void MessagingControls::changeCryptionType()
|
||||||
{
|
{
|
||||||
if (cryptionChoice)
|
(cryptionChoice) ? cryptionSwitch->setText("decrypt chosen") : cryptionSwitch->setText("encrypt chosen");
|
||||||
{
|
cryptionChoice = (cryptionChoice) ? false : true;
|
||||||
cryptionSwitch->setText("decrypt chosen");
|
|
||||||
cryptionChoice = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cryptionSwitch->setText("encrypt chosen");
|
|
||||||
cryptionChoice = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void MessagingControls::determineCryption()
|
void MessagingControls::determineCryption()
|
||||||
{
|
{
|
||||||
if (cryptionChoice)
|
if (cryptionChoice)
|
||||||
{
|
{
|
||||||
Encryption ec{grabCryptionText()};
|
Encryption ec{grabCryptionText()};
|
||||||
ec.encryptMessage();
|
|
||||||
|
|
||||||
textForCryption->clear();
|
textForCryption.get()->clear();
|
||||||
textForCryption->setText(QString::fromStdString(ec.getEncryptedMessage()));
|
textForCryption.get()->setText(QString::fromStdString(ec.getEncryptedMessage()));
|
||||||
|
|
||||||
cryptionSwitch->setText("decrypt chosen");
|
cryptionSwitch.get()->setText("decrypt chosen");
|
||||||
cryptionChoice = false;
|
cryptionChoice = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Decryption dc{grabCryptionText()};
|
Decryption dc{grabCryptionText()};
|
||||||
dc.decryptMessage();
|
|
||||||
|
|
||||||
textForCryption->clear();
|
textForCryption.get()->clear();
|
||||||
textForCryption->setText(QString::fromStdString(dc.getDecryptedMessage()));
|
textForCryption.get()->setText(QString::fromStdString(dc.getDecryptedMessage()));
|
||||||
|
|
||||||
cryptionSwitch->setText("encrypt chosen");
|
cryptionSwitch.get()->setText("encrypt chosen");
|
||||||
cryptionChoice = true;
|
cryptionChoice = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MessagingControls::keyManagementWindow()
|
void MessagingControls::keyManagementWindow()
|
||||||
{
|
{
|
||||||
KeyManagementWindow* kh = new KeyManagementWindow;
|
kh = unique_ptr<KeyManagementWindow>{new KeyManagementWindow};
|
||||||
kh->show();
|
kh.get()->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string MessagingControls::grabCryptionText()
|
std::string MessagingControls::grabCryptionText()
|
||||||
{
|
{
|
||||||
QString placeHolder = textForCryption->toPlainText();
|
auto placeHolder = textForCryption.get()->toPlainText();
|
||||||
std::string message = placeHolder.toStdString();
|
|
||||||
|
|
||||||
return message;
|
return placeHolder.toStdString();
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-20
@@ -14,6 +14,8 @@
|
|||||||
#include<QDockWidget>
|
#include<QDockWidget>
|
||||||
#include<QWidget>
|
#include<QWidget>
|
||||||
#include<QString>
|
#include<QString>
|
||||||
|
#include<memory>
|
||||||
|
#include"KeyManagementWindow.h"
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
@@ -25,52 +27,52 @@ class QMenu;
|
|||||||
class QAction;
|
class QAction;
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
|
using std::unique_ptr;
|
||||||
|
|
||||||
class MessagingControls : public QMainWindow
|
class MessagingControls : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MessagingControls();
|
MessagingControls();
|
||||||
~MessagingControls();
|
~MessagingControls() = default;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void changeCryptionType();
|
void changeCryptionType();
|
||||||
void determineCryption();
|
void determineCryption();
|
||||||
void keyManagementWindow();
|
void keyManagementWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupMainWindow();
|
void setupMainWindow();
|
||||||
void createMenus();
|
void createMenus();
|
||||||
QVBoxLayout* buttonLayout;
|
|
||||||
|
|
||||||
QWidget* buttonWidget;
|
unique_ptr<QVBoxLayout> buttonLayout;
|
||||||
|
|
||||||
QDockWidget* buttonDockWidget;
|
unique_ptr<QWidget> buttonWidget;
|
||||||
QDockWidget* cryptionArea;
|
|
||||||
|
|
||||||
QLabel* lblOfEncryptedBox;
|
unique_ptr<QDockWidget> buttonDockWidget;
|
||||||
QLineEdit* encryptedBox;
|
unique_ptr<QDockWidget> cryptionArea;
|
||||||
|
|
||||||
QTextEdit* textForCryption;
|
unique_ptr<QLabel> lblOfEncryptedBox;
|
||||||
QTextEdit* textToDecrypt;
|
unique_ptr<QLineEdit> encryptedBox;
|
||||||
|
|
||||||
QPushButton* cryptionButon;
|
unique_ptr<QTextEdit> textForCryption;
|
||||||
QPushButton* cryptionSwitch;
|
unique_ptr<QTextEdit> textToDecrypt;
|
||||||
|
|
||||||
QMenu* fileMenu;
|
unique_ptr<QPushButton> cryptionButon;
|
||||||
QMenu* editMenu;
|
unique_ptr<QPushButton> cryptionSwitch;
|
||||||
QAction* closeApplication;
|
|
||||||
QAction* keyEdit;
|
|
||||||
|
|
||||||
|
unique_ptr<QMenu> fileMenu;
|
||||||
|
unique_ptr<QMenu> editMenu;
|
||||||
|
unique_ptr<QAction> closeApplication;
|
||||||
|
unique_ptr<QAction> keyEdit;
|
||||||
|
|
||||||
|
unique_ptr<KeyManagementWindow> kh;
|
||||||
|
|
||||||
std::string grabCryptionText();
|
std::string grabCryptionText();
|
||||||
|
|
||||||
int mainWindowHeight{450};
|
int mainWindowHeight{450};
|
||||||
int mainWindowWidth{550};
|
int mainWindowWidth{550};
|
||||||
|
|
||||||
bool cryptionChoice{};
|
bool cryptionChoice{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user