From 9894385576894a363383ae4548da7efe1b87c664 Mon Sep 17 00:00:00 2001 From: amazing-username Date: Sun, 26 Mar 2017 19:48:21 -0500 Subject: [PATCH] Added more controls to the skeleton, added a base class, updated some elements --- Cryption.cpp | 22 +++++++ Cryption.h | 24 ++++++++ Decryption.cpp | 20 +++---- Decryption.h | 10 ++-- EncryptedMessaging.pro | 3 +- Encryption.cpp | 18 ++---- Encryption.h | 10 ++-- Main.cpp | 1 - Makefile | 19 +++++-- MessagingControls.cpp | 126 +++++++++++++++++++++++++---------------- MessagingControls.h | 31 ++++++++-- 11 files changed, 187 insertions(+), 97 deletions(-) create mode 100644 Cryption.cpp create mode 100644 Cryption.h diff --git a/Cryption.cpp b/Cryption.cpp new file mode 100644 index 0000000..69a032a --- /dev/null +++ b/Cryption.cpp @@ -0,0 +1,22 @@ +#include "Cryption.h" + +Cryption::Cryption() +{ + +} +Cryption::Cryption(const std::string& message) +{ + this->message = message; +} + + +void Cryption::setMessage(const std::string& message) +{ + this->message = message; +} + + +std::string Cryption::getMessage() const +{ + return message; +} diff --git a/Cryption.h b/Cryption.h new file mode 100644 index 0000000..ba97566 --- /dev/null +++ b/Cryption.h @@ -0,0 +1,24 @@ +#ifndef CRYPTION_H +#define CRYPTION_H + +#include +#include + +class Cryption +{ +public: + Cryption(); + Cryption(const std::string&); + + void setMessage(const std::string&); + + std::string getMessage() const; + +protected: + std::string message; + std::fstream ioEvent; + +private: +}; + +#endif diff --git a/Decryption.cpp b/Decryption.cpp index 2660ab4..63cd338 100644 --- a/Decryption.cpp +++ b/Decryption.cpp @@ -9,28 +9,28 @@ Decryption::Decryption() { } - - -void Decryption::setMessage(const std::string message) +Decryption::Decryption(const std::string& message) { this->message = message; } + + void Decryption::decryptMessage() { GenerateKeys gk; - readFromFile.open("encryptedFile.txt", std::ios::in); + ioEvent.open("encryptedFile.txt", std::ios::in); std::string messageToBeDecrypted, decryptedMessage; - while(!readFromFile.eof()) + while(!ioEvent.eof()) { char whiteSpace = static_cast(32); //std::cout << "Am I stuck?" << std::endl; - getline(readFromFile, messageToBeDecrypted, whiteSpace); + getline(ioEvent, messageToBeDecrypted, whiteSpace); } - readFromFile.close(); + ioEvent.close(); unsigned short encryptedTwoKey = 2; unsigned short beginningOfAlphabetLowerCase = 97; @@ -67,9 +67,3 @@ void Decryption::decryptMessage() } setMessage(decryptedMessage); } - - -std::string Decryption::getMessage() const -{ - return message; -} diff --git a/Decryption.h b/Decryption.h index 50499b3..b31e4a6 100644 --- a/Decryption.h +++ b/Decryption.h @@ -4,20 +4,18 @@ #include #include -class Decryption +#include "Cryption.h" + +class Decryption : public Cryption { public: Decryption(); + Decryption(const std::string&); - void setMessage(const std::string); void decryptMessage(); - std::string getMessage() const; - private: - std::fstream readFromFile; - std::string message; }; #endif diff --git a/EncryptedMessaging.pro b/EncryptedMessaging.pro index 261e23d..9f1c43c 100644 --- a/EncryptedMessaging.pro +++ b/EncryptedMessaging.pro @@ -9,9 +9,10 @@ QT += widgets INCLUDEPATH += . # Input -HEADERS += Decryption.h Encryption.h GenerateKeys.h MessagingControls.h +HEADERS += Decryption.h Encryption.h GenerateKeys.h MessagingControls.h Cryption.h SOURCES += Decryption.cpp \ Encryption.cpp \ + Cryption.cpp \ GenerateKeys.cpp \ Main.cpp \ MessagingControls.cpp diff --git a/Encryption.cpp b/Encryption.cpp index c80b649..2a77ea8 100644 --- a/Encryption.cpp +++ b/Encryption.cpp @@ -7,29 +7,23 @@ Encryption::Encryption() { } - - -void Encryption::setMessage(const std::string message) +Encryption::Encryption(const std::string& message) { this->message = message; } + + void Encryption::encryptMessage() { GenerateKeys* gk = new GenerateKeys; - writeToFile.open("encryptedFile.txt", std::ios::out); + ioEvent.open("encryptedFile.txt", std::ios::out); for (unsigned short indexOfString = 0; indexOfString < message.size(); indexOfString++) { - writeToFile << gk->encryptedCharacters[message.at(indexOfString)]; + ioEvent << gk->encryptedCharacters[message.at(indexOfString)]; } - writeToFile.close(); + ioEvent.close(); delete gk; } - - -std::string Encryption::getMessage() const -{ - return message; -} diff --git a/Encryption.h b/Encryption.h index cebdc9e..5f6b54b 100644 --- a/Encryption.h +++ b/Encryption.h @@ -4,20 +4,18 @@ #include #include -class Encryption +#include "Cryption.h" + +class Encryption : public Cryption { public: Encryption(); + Encryption(const std::string&); - void setMessage(const std::string); void encryptMessage(); - std::string getMessage() const; - private: - std::fstream writeToFile; - std::string message; }; #endif diff --git a/Main.cpp b/Main.cpp index 89aa3f4..1093fd7 100644 --- a/Main.cpp +++ b/Main.cpp @@ -1,4 +1,3 @@ -#include #include #include "MessagingControls.h" diff --git a/Makefile b/Makefile index bedd26b..fbfb9ed 100644 --- a/Makefile +++ b/Makefile @@ -50,11 +50,13 @@ OBJECTS_DIR = ./ SOURCES = Decryption.cpp \ Encryption.cpp \ + Cryption.cpp \ GenerateKeys.cpp \ Main.cpp \ MessagingControls.cpp moc_MessagingControls.cpp OBJECTS = Decryption.o \ Encryption.o \ + Cryption.o \ GenerateKeys.o \ Main.o \ MessagingControls.o \ @@ -167,8 +169,10 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ EncryptedMessaging.pro Decryption.h \ Encryption.h \ GenerateKeys.h \ - MessagingControls.h Decryption.cpp \ + MessagingControls.h \ + Cryption.h Decryption.cpp \ Encryption.cpp \ + Cryption.cpp \ GenerateKeys.cpp \ Main.cpp \ MessagingControls.cpp @@ -417,8 +421,8 @@ distdir: FORCE @test -d $(DISTDIR) || mkdir -p $(DISTDIR) $(COPY_FILE) --parents $(DIST) $(DISTDIR)/ $(COPY_FILE) --parents /usr/lib/qt/mkspecs/features/data/dummy.cpp $(DISTDIR)/ - $(COPY_FILE) --parents Decryption.h Encryption.h GenerateKeys.h MessagingControls.h $(DISTDIR)/ - $(COPY_FILE) --parents Decryption.cpp Encryption.cpp GenerateKeys.cpp Main.cpp MessagingControls.cpp $(DISTDIR)/ + $(COPY_FILE) --parents Decryption.h Encryption.h GenerateKeys.h MessagingControls.h Cryption.h $(DISTDIR)/ + $(COPY_FILE) --parents Decryption.cpp Encryption.cpp Cryption.cpp GenerateKeys.cpp Main.cpp MessagingControls.cpp $(DISTDIR)/ clean: compiler_clean @@ -473,20 +477,25 @@ compiler_clean: compiler_moc_predefs_clean compiler_moc_header_clean ####### Compile Decryption.o: Decryption.cpp Decryption.h \ + Cryption.h \ GenerateKeys.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Decryption.o Decryption.cpp Encryption.o: Encryption.cpp Encryption.h \ + Cryption.h \ GenerateKeys.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Encryption.o Encryption.cpp +Cryption.o: Cryption.cpp Cryption.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Cryption.o Cryption.cpp + GenerateKeys.o: GenerateKeys.cpp GenerateKeys.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o GenerateKeys.o GenerateKeys.cpp -Main.o: Main.cpp +Main.o: Main.cpp MessagingControls.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Main.o Main.cpp -MessagingControls.o: MessagingControls.cpp +MessagingControls.o: MessagingControls.cpp MessagingControls.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o MessagingControls.o MessagingControls.cpp moc_MessagingControls.o: moc_MessagingControls.cpp diff --git a/MessagingControls.cpp b/MessagingControls.cpp index 7e5b5af..5d1383a 100644 --- a/MessagingControls.cpp +++ b/MessagingControls.cpp @@ -1,7 +1,6 @@ #include -#include -#include -#include +#include +#include #include "MessagingControls.h" @@ -10,49 +9,9 @@ MessagingControls::MessagingControls() /** * Initialize controls */ - //QVBoxLayout* everything = new QVBoxLayout; + cryptionChoice = true; - //menuStuff = new QMenuBar; - //mainWindow = new QMainWindow; - - lblOfEncryptedBox = new QLabel(tr("Message: ")); - - textToEncrypt = new QTextEdit; - //encryptedBox = new QLineEdit; - - encryptionButon = new QPushButton; - - //Adding lbl and line edit - //QHBoxLayout* lblAndLineEdit = new QHBoxLayout; - //lblAndLineEdit->addWidget(lblOfEncryptedBox); - //lblAndLineEdit->addWidget(textToEncrypt); - - //Adding button - //QHBoxLayout* button = new QHBoxLayout; - //button->addWidget(encryptionButon); - - //Add everything - //everything->addLayout(menuStuff); - //everything->addLayout(lblAndLineEdit); - //everything->addLayout(button); - - createMenus(); - - QDockWidget* lblAndArea = new QDockWidget(tr("Dock Widget")); - lblAndArea->setWidget(textToEncrypt); - //lblAndArea->setWidget(lblOfEncryptedBox); - - addDockWidget(Qt::LeftDockWidgetArea, lblAndArea); - - //mainWindow->addDockWidget(Qt::LeftDockWidgetArea, lblAndArea); - //mainWindow->addDockWidget(lblAndArea); - //mainWindow->addDockWidget(textToEncrypt); - //mainWindow->addDockWidget(encryptionButon); - - //setLayout(mainWindow); - setWindowTitle("Encryption Messaging"); - setFixedHeight(300); - setFixedWidth(400); + setupMainWindow(); } MessagingControls::~MessagingControls() { @@ -60,13 +19,47 @@ MessagingControls::~MessagingControls() * Delete pointer types */ delete lblOfEncryptedBox; - delete encryptionButon; - delete textToEncrypt; - //delete encryptedBox; + delete cryptionButon; + delete textForCryption; } +void MessagingControls::setupMainWindow() +{ + textForCryption = new QTextEdit; + + + cryptionButon = new QPushButton(tr("XO")); + cryptionSwitch = new QPushButton(tr("encrypt")); + + + buttonLayout = new QVBoxLayout; + buttonWidget = new QWidget; + buttonDockWidget = new QDockWidget; + buttonDockWidget->setWindowTitle(tr("Cryption Controls")); + buttonLayout->addWidget(cryptionButon); + buttonLayout->addWidget(cryptionSwitch); + buttonWidget->setLayout(buttonLayout); + buttonDockWidget->setWidget(buttonWidget); + buttonDockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); + setCentralWidget(buttonDockWidget); + + QDockWidget* cryptionArea = new QDockWidget(tr("Cryption")); + cryptionArea->setWidget(textForCryption); + cryptionArea->setFeatures(QDockWidget::NoDockWidgetFeatures); + addDockWidget(Qt::LeftDockWidgetArea, cryptionArea); + + createMenus(); + + QObject::connect(closeApplication, SIGNAL(triggered()), this, SLOT(close())); + QObject::connect(cryptionSwitch, SIGNAL(clicked()), this, SLOT(changeCryptionType())); + QObject::connect(cryptionButon, SIGNAL(clicked()), this, SLOT(determineCryption())); + + setWindowTitle("Encryption Decryption Messaging"); + setFixedHeight(mainWindowHeight); + setFixedWidth(mainWindowWidth); +} void MessagingControls::createMenus() { fileMenu = menuBar()->addMenu(tr("File")); @@ -78,5 +71,42 @@ void MessagingControls::createMenus() fileMenu->addAction(closeApplication); editMenu->addAction(keyEdit); +} + + +void MessagingControls::changeCryptionType() +{ + if (cryptionChoice) + { + cryptionSwitch->setText("decrypt"); + cryptionChoice = false; + } + else + { + cryptionSwitch->setText("encrypt"); + cryptionChoice = true; + } +} +void MessagingControls::determineCryption() +{ + if (cryptionChoice) + { + /** + * Decrypt Message + */ + } + else + { + /** + * Encrypt Message + */ + } + //std::string s; + //s = textForCryption->toPlainText().toStdString(); + //std::cout << s << std::endl; + //QString* str = textForCryption->toPlainText(); + //s = str->toStdString(); + //s = static_cast(textForCryption->toPlainText()); + //std::cout << textForCryption->toPlainText() << std::endl; } diff --git a/MessagingControls.h b/MessagingControls.h index 3c1669e..3821ee4 100644 --- a/MessagingControls.h +++ b/MessagingControls.h @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include class QLabel; class QLineEdit; @@ -27,24 +30,42 @@ public: MessagingControls(); ~MessagingControls(); - - signals: private slots: + void changeCryptionType(); + void determineCryption(); private: + void setupMainWindow(); void createMenus(); - QLineEdit* encryptedBox; + QVBoxLayout* buttonLayout; + + QWidget* buttonWidget; + + QDockWidget* buttonDockWidget; + QDockWidget* cryptionArea; + QLabel* lblOfEncryptedBox; - QTextEdit* textToEncrypt; - QPushButton* encryptionButon; + QLineEdit* encryptedBox; + + QTextEdit* textForCryption; + QTextEdit* textToDecrypt; + + QPushButton* cryptionButon; + QPushButton* cryptionSwitch; + QMenu* fileMenu; QMenu* editMenu; QAction* closeApplication; QAction* keyEdit; + + unsigned short mainWindowHeight = 450; + unsigned short mainWindowWidth = 550; + + bool cryptionChoice; }; #endif