Issue #1 #2 #4 are addressed in this commit. Added another window with controls for key management. Simple ASCII encryption
This commit is contained in:
@@ -9,10 +9,11 @@ QT += widgets
|
||||
INCLUDEPATH += .
|
||||
|
||||
# Input
|
||||
HEADERS += Decryption.h Encryption.h GenerateKeys.h MessagingControls.h Cryption.h
|
||||
HEADERS += Decryption.h Encryption.h GenerateKeys.h MessagingControls.h Cryption.h KeyManagementWindow.h
|
||||
SOURCES += Decryption.cpp \
|
||||
Encryption.cpp \
|
||||
Cryption.cpp \
|
||||
KeyManagementWindow.cpp \
|
||||
GenerateKeys.cpp \
|
||||
Main.cpp \
|
||||
MessagingControls.cpp
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "Encryption.h"
|
||||
#include "GenerateKeys.h"
|
||||
@@ -13,6 +15,10 @@ Encryption::Encryption(const std::string& message)
|
||||
}
|
||||
|
||||
|
||||
void Encryption::setEncryptedMessage(const std::string& encryptedMessage)
|
||||
{
|
||||
this->encryptedMessage = encryptedMessage;
|
||||
}
|
||||
void Encryption::encryptMessage()
|
||||
{
|
||||
GenerateKeys* gk = new GenerateKeys;
|
||||
@@ -21,9 +27,18 @@ void Encryption::encryptMessage()
|
||||
for (unsigned short indexOfString = 0; indexOfString < message.size(); indexOfString++)
|
||||
{
|
||||
ioEvent << gk->encryptedCharacters[message.at(indexOfString)];
|
||||
encryptedMessage += std::to_string(gk->encryptedCharacters[message.at(indexOfString)]);
|
||||
std::cout << encryptedMessage << std::endl;
|
||||
}
|
||||
|
||||
setEncryptedMessage(encryptedMessage);
|
||||
ioEvent.close();
|
||||
|
||||
delete gk;
|
||||
}
|
||||
|
||||
|
||||
std::string Encryption::getEncryptedMessage() const
|
||||
{
|
||||
return encryptedMessage;
|
||||
}
|
||||
|
||||
@@ -13,9 +13,13 @@ public:
|
||||
Encryption();
|
||||
Encryption(const std::string&);
|
||||
|
||||
void setEncryptedMessage(const std::string&);
|
||||
void encryptMessage();
|
||||
|
||||
std::string getEncryptedMessage() const;
|
||||
|
||||
private:
|
||||
std::string encryptedMessage;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+4
-5
@@ -4,7 +4,6 @@
|
||||
|
||||
GenerateKeys::GenerateKeys()
|
||||
{
|
||||
|
||||
populateDecryptedValues();
|
||||
populateEncryptedValues();
|
||||
}
|
||||
@@ -16,22 +15,22 @@ void GenerateKeys::populateDecryptedValues()
|
||||
char character;
|
||||
character = static_cast<char>(number);
|
||||
|
||||
if (number >= 97 && number <= 122)
|
||||
if (number >= startingCharacter && number <= endingCharacter)
|
||||
{
|
||||
decryptedCharacters[number] = character;
|
||||
//std::cout << decryptedCharacters[number] << " ";
|
||||
}
|
||||
}
|
||||
//std::cout << std::endl;
|
||||
decryptedCharacters[32] = ' ';
|
||||
decryptedCharacters[whiteSpaceCharacter] = ' ';
|
||||
}
|
||||
void GenerateKeys::populateEncryptedValues()
|
||||
{
|
||||
for (unsigned short key = 97; key <= 122; key++)
|
||||
for (unsigned short key = startingCharacter; key <= endingCharacter; key++)
|
||||
{
|
||||
encryptedCharacters[decryptedCharacters[key]] = key;
|
||||
//std::cout << encryptedCharacters[decryptedCharacters[key]] << " ";
|
||||
}
|
||||
encryptedCharacters[decryptedCharacters[32]] = 32;
|
||||
encryptedCharacters[decryptedCharacters[startingCharacter]] = startingCharacter;
|
||||
//std::cout << std::endl;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,14 @@ public:
|
||||
|
||||
friend class Encryption;
|
||||
friend class Decryption;
|
||||
friend class KeyManagementWindow;
|
||||
|
||||
private:
|
||||
std::map<unsignedShort, char> decryptedCharacters;
|
||||
std::map<char, unsignedShort> encryptedCharacters;
|
||||
unsigned short startingCharacter = 97;
|
||||
unsigned short endingCharacter = 122;
|
||||
unsigned short whiteSpaceCharacter = 32;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "KeyManagementWindow.h"
|
||||
#include "GenerateKeys.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QString>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
|
||||
KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent)
|
||||
{
|
||||
GenerateKeys gk;
|
||||
|
||||
comboBoxOfKeys = new QComboBox;
|
||||
valueOfKey = new QLineEdit;
|
||||
|
||||
QVBoxLayout* vBox = new QVBoxLayout;
|
||||
QHBoxLayout* hBox = new QHBoxLayout;
|
||||
|
||||
setContentsOfComboBox();
|
||||
hBox->addWidget(comboBoxOfKeys);
|
||||
hBox->addWidget(valueOfKey);
|
||||
|
||||
vBox->addLayout(hBox);
|
||||
|
||||
setLayout(vBox);
|
||||
|
||||
setFixedWidth(400);
|
||||
setFixedHeight(400);
|
||||
|
||||
setWindowTitle("Key Management Window");
|
||||
|
||||
QObject::connect(comboBoxOfKeys, SIGNAL(currentIndexChanged(int)), SLOT(test()));
|
||||
}
|
||||
|
||||
|
||||
void KeyManagementWindow::setContentsOfComboBox()
|
||||
{
|
||||
GenerateKeys gk;
|
||||
|
||||
for (unsigned short keyIndex = gk.startingCharacter; keyIndex <= gk.endingCharacter; keyIndex++)
|
||||
{
|
||||
std::string ch = "";
|
||||
ch += gk.decryptedCharacters[keyIndex];
|
||||
QString bl = QString::fromStdString(ch);
|
||||
comboBoxOfKeys->addItem(bl);
|
||||
}
|
||||
}
|
||||
void KeyManagementWindow::test()
|
||||
{
|
||||
GenerateKeys gk;
|
||||
//std::cout << "bang bang!" << std::endl;
|
||||
QString bo = comboBoxOfKeys->currentText();
|
||||
std::string k = bo.toStdString();
|
||||
char f;
|
||||
|
||||
std::fstream in;
|
||||
in.open("strToCh.txt", std::ios::out);
|
||||
|
||||
in << k;
|
||||
in.close();
|
||||
|
||||
in.open("strToCh.txt", std::ios::in);
|
||||
|
||||
in >> f;
|
||||
in.close();
|
||||
|
||||
in.open("strToCh.txt", std::ios::out);
|
||||
in << gk.encryptedCharacters[f];
|
||||
in.close();
|
||||
|
||||
unsigned short yek;
|
||||
in.open("strToCh.txt", std::ios::in);
|
||||
in >> yek;
|
||||
in.close();
|
||||
|
||||
std::string key = "";
|
||||
key += std::to_string(yek);
|
||||
//std::cout << gk.encryptedCharacters[f] << std::endl;
|
||||
QString v = QString::fromStdString(key);
|
||||
valueOfKey->setText(v);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef KEYMANAGEMENTWINDOW_H
|
||||
#define KEYMANAGEMENTWINDOW_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
|
||||
class KeyManagementWindow : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KeyManagementWindow(QWidget* parent = 0);
|
||||
|
||||
void setContentsOfComboBox();
|
||||
private slots:
|
||||
void test();
|
||||
private:
|
||||
QComboBox* comboBoxOfKeys;
|
||||
QLineEdit* valueOfKey;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -51,16 +51,20 @@ OBJECTS_DIR = ./
|
||||
SOURCES = Decryption.cpp \
|
||||
Encryption.cpp \
|
||||
Cryption.cpp \
|
||||
KeyManagementWindow.cpp \
|
||||
GenerateKeys.cpp \
|
||||
Main.cpp \
|
||||
MessagingControls.cpp moc_MessagingControls.cpp
|
||||
MessagingControls.cpp moc_MessagingControls.cpp \
|
||||
moc_KeyManagementWindow.cpp
|
||||
OBJECTS = Decryption.o \
|
||||
Encryption.o \
|
||||
Cryption.o \
|
||||
KeyManagementWindow.o \
|
||||
GenerateKeys.o \
|
||||
Main.o \
|
||||
MessagingControls.o \
|
||||
moc_MessagingControls.o
|
||||
moc_MessagingControls.o \
|
||||
moc_KeyManagementWindow.o
|
||||
DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \
|
||||
/usr/lib/qt/mkspecs/common/unix.conf \
|
||||
/usr/lib/qt/mkspecs/common/linux.conf \
|
||||
@@ -170,9 +174,11 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \
|
||||
Encryption.h \
|
||||
GenerateKeys.h \
|
||||
MessagingControls.h \
|
||||
Cryption.h Decryption.cpp \
|
||||
Cryption.h \
|
||||
KeyManagementWindow.h Decryption.cpp \
|
||||
Encryption.cpp \
|
||||
Cryption.cpp \
|
||||
KeyManagementWindow.cpp \
|
||||
GenerateKeys.cpp \
|
||||
Main.cpp \
|
||||
MessagingControls.cpp
|
||||
@@ -421,8 +427,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 Cryption.h $(DISTDIR)/
|
||||
$(COPY_FILE) --parents Decryption.cpp Encryption.cpp Cryption.cpp GenerateKeys.cpp Main.cpp MessagingControls.cpp $(DISTDIR)/
|
||||
$(COPY_FILE) --parents Decryption.h Encryption.h GenerateKeys.h MessagingControls.h Cryption.h KeyManagementWindow.h $(DISTDIR)/
|
||||
$(COPY_FILE) --parents Decryption.cpp Encryption.cpp Cryption.cpp KeyManagementWindow.cpp GenerateKeys.cpp Main.cpp MessagingControls.cpp $(DISTDIR)/
|
||||
|
||||
|
||||
clean: compiler_clean
|
||||
@@ -454,14 +460,19 @@ 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 moc_KeyManagementWindow.cpp
|
||||
compiler_moc_header_clean:
|
||||
-$(DEL_FILE) moc_MessagingControls.cpp
|
||||
-$(DEL_FILE) moc_MessagingControls.cpp moc_KeyManagementWindow.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
|
||||
|
||||
moc_KeyManagementWindow.cpp: KeyManagementWindow.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 KeyManagementWindow.h -o moc_KeyManagementWindow.cpp
|
||||
|
||||
compiler_moc_source_make_all:
|
||||
compiler_moc_source_clean:
|
||||
compiler_uic_make_all:
|
||||
@@ -489,6 +500,9 @@ Encryption.o: Encryption.cpp Encryption.h \
|
||||
Cryption.o: Cryption.cpp Cryption.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Cryption.o Cryption.cpp
|
||||
|
||||
KeyManagementWindow.o: KeyManagementWindow.cpp KeyManagementWindow.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o KeyManagementWindow.o KeyManagementWindow.cpp
|
||||
|
||||
GenerateKeys.o: GenerateKeys.cpp GenerateKeys.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o GenerateKeys.o GenerateKeys.cpp
|
||||
|
||||
@@ -501,6 +515,9 @@ MessagingControls.o: MessagingControls.cpp MessagingControls.h
|
||||
moc_MessagingControls.o: moc_MessagingControls.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_MessagingControls.o moc_MessagingControls.cpp
|
||||
|
||||
moc_KeyManagementWindow.o: moc_KeyManagementWindow.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_KeyManagementWindow.o moc_KeyManagementWindow.cpp
|
||||
|
||||
####### Install
|
||||
|
||||
install: FORCE
|
||||
|
||||
+30
-3
@@ -3,6 +3,8 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "MessagingControls.h"
|
||||
#include "KeyManagementWindow.h"
|
||||
#include "Encryption.h"
|
||||
|
||||
MessagingControls::MessagingControls()
|
||||
{
|
||||
@@ -28,10 +30,12 @@ MessagingControls::~MessagingControls()
|
||||
void MessagingControls::setupMainWindow()
|
||||
{
|
||||
textForCryption = new QTextEdit;
|
||||
textForCryption->setText("sdfs");
|
||||
textForCryption->clear();
|
||||
|
||||
|
||||
cryptionButon = new QPushButton(tr("XO"));
|
||||
cryptionSwitch = new QPushButton(tr("encrypt"));
|
||||
cryptionSwitch = new QPushButton(tr("encrypt chosen"));
|
||||
|
||||
|
||||
buttonLayout = new QVBoxLayout;
|
||||
@@ -55,6 +59,7 @@ void MessagingControls::setupMainWindow()
|
||||
QObject::connect(closeApplication, SIGNAL(triggered()), this, SLOT(close()));
|
||||
QObject::connect(cryptionSwitch, SIGNAL(clicked()), this, SLOT(changeCryptionType()));
|
||||
QObject::connect(cryptionButon, SIGNAL(clicked()), this, SLOT(determineCryption()));
|
||||
QObject::connect(keyEdit, SIGNAL(triggered()), this, SLOT(keyManagementWindow()));
|
||||
|
||||
setWindowTitle("Encryption Decryption Messaging");
|
||||
setFixedHeight(mainWindowHeight);
|
||||
@@ -78,12 +83,12 @@ void MessagingControls::changeCryptionType()
|
||||
{
|
||||
if (cryptionChoice)
|
||||
{
|
||||
cryptionSwitch->setText("decrypt");
|
||||
cryptionSwitch->setText("decrypt chosen");
|
||||
cryptionChoice = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
cryptionSwitch->setText("encrypt");
|
||||
cryptionSwitch->setText("encrypt chosen");
|
||||
cryptionChoice = true;
|
||||
}
|
||||
}
|
||||
@@ -91,6 +96,21 @@ void MessagingControls::determineCryption()
|
||||
{
|
||||
if (cryptionChoice)
|
||||
{
|
||||
QString content;
|
||||
content = textForCryption->toPlainText();
|
||||
std::string message = content.toStdString();
|
||||
|
||||
Encryption ec;
|
||||
ec.setMessage(message);
|
||||
ec.encryptMessage();
|
||||
|
||||
std::cout << ec.getEncryptedMessage() << std::endl;
|
||||
QString messageQ = QString::fromStdString(ec.getEncryptedMessage());
|
||||
textForCryption->clear();
|
||||
textForCryption->setText(messageQ);
|
||||
|
||||
cryptionSwitch->setText("decrypt chosen");
|
||||
cryptionChoice = false;
|
||||
/**
|
||||
* Decrypt Message
|
||||
*/
|
||||
@@ -110,3 +130,10 @@ void MessagingControls::determineCryption()
|
||||
//std::cout << textForCryption->toPlainText() << std::endl;
|
||||
|
||||
}
|
||||
void MessagingControls::keyManagementWindow()
|
||||
{
|
||||
KeyManagementWindow* kh = new KeyManagementWindow;
|
||||
|
||||
kh->show();
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ signals:
|
||||
private slots:
|
||||
void changeCryptionType();
|
||||
void determineCryption();
|
||||
void keyManagementWindow();
|
||||
|
||||
private:
|
||||
void setupMainWindow();
|
||||
|
||||
Reference in New Issue
Block a user