diff --git a/Decryption.cpp b/Decryption.cpp new file mode 100644 index 0000000..2660ab4 --- /dev/null +++ b/Decryption.cpp @@ -0,0 +1,75 @@ +#include +#include +#include + +#include "Decryption.h" +#include "GenerateKeys.h" + +Decryption::Decryption() +{ + +} + + +void Decryption::setMessage(const std::string message) +{ + this->message = message; +} +void Decryption::decryptMessage() +{ + GenerateKeys gk; + + readFromFile.open("encryptedFile.txt", std::ios::in); + + std::string messageToBeDecrypted, decryptedMessage; + + while(!readFromFile.eof()) + { + char whiteSpace = static_cast(32); + //std::cout << "Am I stuck?" << std::endl; + getline(readFromFile, messageToBeDecrypted, whiteSpace); + } + + readFromFile.close(); + + unsigned short encryptedTwoKey = 2; + unsigned short beginningOfAlphabetLowerCase = 97; + unsigned short endingOfAplphabetLowerCase = 122; + unsigned short whiteSpaceASCIICode = 32; + for (unsigned short index = 0; index < messageToBeDecrypted.size(); index++) + { + if ((index + encryptedTwoKey) < messageToBeDecrypted.size()) + { + char otherElements[] = {messageToBeDecrypted.at(index), messageToBeDecrypted.at(index + 1), messageToBeDecrypted.at(index + 2)}; + unsigned short number = atoi(otherElements); + + if ((number > endingOfAplphabetLowerCase || number < beginningOfAlphabetLowerCase) && (number != whiteSpaceASCIICode)) + { + otherElements[0] = {messageToBeDecrypted.at(index)}; + otherElements[1] = {messageToBeDecrypted.at(index + 1)}; + otherElements[2] = {' '}; + number = atoi(otherElements); + decryptedMessage += gk.decryptedCharacters[number]; + //decryptedMessage.append(gk.decryptedCharacters[number]); + //newWord += characters[number]; + index += 1; + + } + else + { + decryptedMessage += gk.decryptedCharacters[number]; + //decryptedMessage.append(gk.decryptedCharacters[number]); + //newWord += characters[number]; + index += 2; + + } + } + } + setMessage(decryptedMessage); +} + + +std::string Decryption::getMessage() const +{ + return message; +} diff --git a/Decryption.h b/Decryption.h new file mode 100644 index 0000000..50499b3 --- /dev/null +++ b/Decryption.h @@ -0,0 +1,23 @@ +#ifndef DECRYPTION_H +#define DECRYPTION_H + +#include +#include + +class Decryption +{ +public: + + Decryption(); + + void setMessage(const std::string); + void decryptMessage(); + + std::string getMessage() const; + +private: + std::fstream readFromFile; + std::string message; +}; + +#endif diff --git a/Decryption.h.gch b/Decryption.h.gch new file mode 100644 index 0000000..014f2f3 Binary files /dev/null and b/Decryption.h.gch differ diff --git a/Encryption.cpp b/Encryption.cpp new file mode 100644 index 0000000..c80b649 --- /dev/null +++ b/Encryption.cpp @@ -0,0 +1,35 @@ +#include + +#include "Encryption.h" +#include "GenerateKeys.h" + +Encryption::Encryption() +{ + +} + + +void Encryption::setMessage(const std::string message) +{ + this->message = message; +} +void Encryption::encryptMessage() +{ + GenerateKeys* gk = new GenerateKeys; + writeToFile.open("encryptedFile.txt", std::ios::out); + + for (unsigned short indexOfString = 0; indexOfString < message.size(); indexOfString++) + { + writeToFile << gk->encryptedCharacters[message.at(indexOfString)]; + } + + writeToFile.close(); + + delete gk; +} + + +std::string Encryption::getMessage() const +{ + return message; +} diff --git a/Encryption.h b/Encryption.h new file mode 100644 index 0000000..cebdc9e --- /dev/null +++ b/Encryption.h @@ -0,0 +1,23 @@ +#ifndef ENCRYPTION_H +#define ENCRYPTION_H + +#include +#include + +class Encryption +{ +public: + + Encryption(); + + void setMessage(const std::string); + void encryptMessage(); + + std::string getMessage() const; + +private: + std::fstream writeToFile; + std::string message; +}; + +#endif diff --git a/Encryption.h.gch b/Encryption.h.gch new file mode 100644 index 0000000..c9088f4 Binary files /dev/null and b/Encryption.h.gch differ diff --git a/GenerateKeys.cpp b/GenerateKeys.cpp new file mode 100644 index 0000000..80d4ed0 --- /dev/null +++ b/GenerateKeys.cpp @@ -0,0 +1,37 @@ +#include + +#include "GenerateKeys.h" + +GenerateKeys::GenerateKeys() +{ + + populateDecryptedValues(); + populateEncryptedValues(); +} + +void GenerateKeys::populateDecryptedValues() +{ + for (unsigned short number = 0; number < 300; number++) + { + char character; + character = static_cast(number); + + if (number >= 97 && number <= 122) + { + decryptedCharacters[number] = character; + //std::cout << decryptedCharacters[number] << " "; + } + } + //std::cout << std::endl; + decryptedCharacters[32] = ' '; +} +void GenerateKeys::populateEncryptedValues() +{ + for (unsigned short key = 97; key <= 122; key++) + { + encryptedCharacters[decryptedCharacters[key]] = key; + //std::cout << encryptedCharacters[decryptedCharacters[key]] << " "; + } + encryptedCharacters[decryptedCharacters[32]] = 32; + //std::cout << std::endl; +} diff --git a/GenerateKeys.h b/GenerateKeys.h new file mode 100644 index 0000000..22842d6 --- /dev/null +++ b/GenerateKeys.h @@ -0,0 +1,24 @@ +#ifndef GENERATEKEYS_H +#define GENERATEKEYS_H + +#include + +class GenerateKeys +{ +public: + typedef unsigned short unsignedShort; + + GenerateKeys(); + + void populateDecryptedValues(); + void populateEncryptedValues(); + + friend class Encryption; + friend class Decryption; + +private: + std::map decryptedCharacters; + std::map encryptedCharacters; +}; + +#endif diff --git a/GenerateKeys.h.gch b/GenerateKeys.h.gch new file mode 100644 index 0000000..d3956c8 Binary files /dev/null and b/GenerateKeys.h.gch differ diff --git a/Main.cpp b/Main.cpp new file mode 100644 index 0000000..89aa3f4 --- /dev/null +++ b/Main.cpp @@ -0,0 +1,14 @@ +#include +#include + +#include "MessagingControls.h" + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + MessagingControls* stuff = new MessagingControls;; + + stuff->show(); + + return app.exec(); +} diff --git a/Makefile b/Makefile index 5511ecb..bedd26b 100644 --- a/Makefile +++ b/Makefile @@ -48,11 +48,17 @@ OBJECTS_DIR = ./ ####### Files -SOURCES = main.cpp \ - messagingcontrols.cpp moc_messagingcontrols.cpp -OBJECTS = main.o \ - messagingcontrols.o \ - moc_messagingcontrols.o +SOURCES = Decryption.cpp \ + Encryption.cpp \ + GenerateKeys.cpp \ + Main.cpp \ + MessagingControls.cpp moc_MessagingControls.cpp +OBJECTS = Decryption.o \ + Encryption.o \ + GenerateKeys.o \ + Main.o \ + MessagingControls.o \ + moc_MessagingControls.o DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/common/unix.conf \ /usr/lib/qt/mkspecs/common/linux.conf \ @@ -158,8 +164,14 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/features/exceptions.prf \ /usr/lib/qt/mkspecs/features/yacc.prf \ /usr/lib/qt/mkspecs/features/lex.prf \ - EncryptedMessaging.pro messagingcontrols.h main.cpp \ - messagingcontrols.cpp + EncryptedMessaging.pro Decryption.h \ + Encryption.h \ + GenerateKeys.h \ + MessagingControls.h Decryption.cpp \ + Encryption.cpp \ + GenerateKeys.cpp \ + Main.cpp \ + MessagingControls.cpp QMAKE_TARGET = EncryptedMessaging DESTDIR = TARGET = EncryptedMessaging @@ -405,8 +417,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 messagingcontrols.h $(DISTDIR)/ - $(COPY_FILE) --parents main.cpp messagingcontrols.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)/ clean: compiler_clean @@ -438,13 +450,13 @@ compiler_moc_predefs_clean: moc_predefs.h: /usr/lib/qt/mkspecs/features/data/dummy.cpp g++ -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -dM -E -o moc_predefs.h /usr/lib/qt/mkspecs/features/data/dummy.cpp -compiler_moc_header_make_all: moc_messagingcontrols.cpp +compiler_moc_header_make_all: moc_MessagingControls.cpp compiler_moc_header_clean: - -$(DEL_FILE) moc_messagingcontrols.cpp -moc_messagingcontrols.cpp: messagingcontrols.h \ + -$(DEL_FILE) moc_MessagingControls.cpp +moc_MessagingControls.cpp: MessagingControls.h \ moc_predefs.h \ /usr/bin/moc - /usr/bin/moc $(DEFINES) --include ./moc_predefs.h -I/usr/lib/qt/mkspecs/linux-g++ -I/home/monde/Programming/Qt/EncryptedMessaging -I/home/monde/Programming/Qt/EncryptedMessaging -I/usr/include/qt -I/usr/include/qt/QtWidgets -I/usr/include/qt/QtGui -I/usr/include/qt/QtCore -I/usr/include/c++/6.3.1 -I/usr/include/c++/6.3.1/x86_64-pc-linux-gnu -I/usr/include/c++/6.3.1/backward -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include -I/usr/local/include -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include-fixed -I/usr/include messagingcontrols.h -o moc_messagingcontrols.cpp + /usr/bin/moc $(DEFINES) --include ./moc_predefs.h -I/usr/lib/qt/mkspecs/linux-g++ -I/home/monde/Programming/Qt/EncryptedMessaging -I/home/monde/Programming/Qt/EncryptedMessaging -I/usr/include/qt -I/usr/include/qt/QtWidgets -I/usr/include/qt/QtGui -I/usr/include/qt/QtCore -I/usr/include/c++/6.3.1 -I/usr/include/c++/6.3.1/x86_64-pc-linux-gnu -I/usr/include/c++/6.3.1/backward -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include -I/usr/local/include -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include-fixed -I/usr/include MessagingControls.h -o moc_MessagingControls.cpp compiler_moc_source_make_all: compiler_moc_source_clean: @@ -460,14 +472,25 @@ compiler_clean: compiler_moc_predefs_clean compiler_moc_header_clean ####### Compile -main.o: main.cpp messagingcontrols.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp +Decryption.o: Decryption.cpp Decryption.h \ + GenerateKeys.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Decryption.o Decryption.cpp -messagingcontrols.o: messagingcontrols.cpp messagingcontrols.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o messagingcontrols.o messagingcontrols.cpp +Encryption.o: Encryption.cpp Encryption.h \ + GenerateKeys.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Encryption.o Encryption.cpp -moc_messagingcontrols.o: moc_messagingcontrols.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_messagingcontrols.o moc_messagingcontrols.cpp +GenerateKeys.o: GenerateKeys.cpp GenerateKeys.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o GenerateKeys.o GenerateKeys.cpp + +Main.o: Main.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Main.o Main.cpp + +MessagingControls.o: MessagingControls.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o MessagingControls.o MessagingControls.cpp + +moc_MessagingControls.o: moc_MessagingControls.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_MessagingControls.o moc_MessagingControls.cpp ####### Install diff --git a/MessagingControls.cpp b/MessagingControls.cpp new file mode 100644 index 0000000..7febd76 --- /dev/null +++ b/MessagingControls.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#include "MessagingControls.h" + +MessagingControls::MessagingControls(QWidget* parent) : QDialog(parent) +{ + /** + * Initialize controls + */ + QVBoxLayout* everything = new QVBoxLayout; + + //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); + + QDockWidget* lblAndArea = new QDockWidget(tr("Dock Widget")); + lblAndArea->setWidget(textToEncrypt); + + mainWindow->addDockWidget(Qt::LeftDockWidgetArea, lblAndArea); + //mainWindow->addDockWidget(lblAndArea); + //mainWindow->addDockWidget(textToEncrypt); + //mainWindow->addDockWidget(encryptionButon); + + //setLayout(mainWindow); + setWindowTitle("Encryption Messaging"); + setFixedHeight(300); + setFixedWidth(400); +} +MessagingControls::~MessagingControls() +{ + /** + * Delete pointer types + */ + delete lblOfEncryptedBox; + delete encryptionButon; + delete textToEncrypt; + //delete encryptedBox; + +} diff --git a/MessagingControls.h b/MessagingControls.h new file mode 100644 index 0000000..da8db9d --- /dev/null +++ b/MessagingControls.h @@ -0,0 +1,40 @@ +#ifndef MESSAGINGCONTROLS_H +#define MESSAGINGCONTROLS_H + +#include +#include +#include +#include +#include +#include +#include + +class QLabel; +class QLineEdit; +class QTextEdit; +class QPushButton; +class QMenuBar; +class QMainWindow; + +class MessagingControls : public QDialog +{ + Q_OBJECT +public: + MessagingControls(QWidget* parent = 0); + ~MessagingControls(); + +signals: + + +private slots: + +private: + QLineEdit* encryptedBox; + QLabel* lblOfEncryptedBox; + QTextEdit* textToEncrypt; + QPushButton* encryptionButon; + QMenuBar* menuStuff; + QMainWindow* mainWindow; +}; + +#endif