Added classes for Encryption and Decryption
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <ios>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#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<char>(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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef DECRYPTION_H
|
||||||
|
#define DECRYPTION_H
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Decryption
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Decryption();
|
||||||
|
|
||||||
|
void setMessage(const std::string);
|
||||||
|
void decryptMessage();
|
||||||
|
|
||||||
|
std::string getMessage() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::fstream readFromFile;
|
||||||
|
std::string message;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Binary file not shown.
@@ -0,0 +1,35 @@
|
|||||||
|
#include <ios>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef ENCRYPTION_H
|
||||||
|
#define ENCRYPTION_H
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Encryption
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Encryption();
|
||||||
|
|
||||||
|
void setMessage(const std::string);
|
||||||
|
void encryptMessage();
|
||||||
|
|
||||||
|
std::string getMessage() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::fstream writeToFile;
|
||||||
|
std::string message;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Binary file not shown.
@@ -0,0 +1,37 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "GenerateKeys.h"
|
||||||
|
|
||||||
|
GenerateKeys::GenerateKeys()
|
||||||
|
{
|
||||||
|
|
||||||
|
populateDecryptedValues();
|
||||||
|
populateEncryptedValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenerateKeys::populateDecryptedValues()
|
||||||
|
{
|
||||||
|
for (unsigned short number = 0; number < 300; number++)
|
||||||
|
{
|
||||||
|
char character;
|
||||||
|
character = static_cast<char>(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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef GENERATEKEYS_H
|
||||||
|
#define GENERATEKEYS_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
class GenerateKeys
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef unsigned short unsignedShort;
|
||||||
|
|
||||||
|
GenerateKeys();
|
||||||
|
|
||||||
|
void populateDecryptedValues();
|
||||||
|
void populateEncryptedValues();
|
||||||
|
|
||||||
|
friend class Encryption;
|
||||||
|
friend class Decryption;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<unsignedShort, char> decryptedCharacters;
|
||||||
|
std::map<char, unsignedShort> encryptedCharacters;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Binary file not shown.
@@ -0,0 +1,14 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include "MessagingControls.h"
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
MessagingControls* stuff = new MessagingControls;;
|
||||||
|
|
||||||
|
stuff->show();
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
@@ -48,11 +48,17 @@ OBJECTS_DIR = ./
|
|||||||
|
|
||||||
####### Files
|
####### Files
|
||||||
|
|
||||||
SOURCES = main.cpp \
|
SOURCES = Decryption.cpp \
|
||||||
messagingcontrols.cpp moc_messagingcontrols.cpp
|
Encryption.cpp \
|
||||||
OBJECTS = main.o \
|
GenerateKeys.cpp \
|
||||||
messagingcontrols.o \
|
Main.cpp \
|
||||||
moc_messagingcontrols.o
|
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 \
|
DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \
|
||||||
/usr/lib/qt/mkspecs/common/unix.conf \
|
/usr/lib/qt/mkspecs/common/unix.conf \
|
||||||
/usr/lib/qt/mkspecs/common/linux.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/exceptions.prf \
|
||||||
/usr/lib/qt/mkspecs/features/yacc.prf \
|
/usr/lib/qt/mkspecs/features/yacc.prf \
|
||||||
/usr/lib/qt/mkspecs/features/lex.prf \
|
/usr/lib/qt/mkspecs/features/lex.prf \
|
||||||
EncryptedMessaging.pro messagingcontrols.h main.cpp \
|
EncryptedMessaging.pro Decryption.h \
|
||||||
messagingcontrols.cpp
|
Encryption.h \
|
||||||
|
GenerateKeys.h \
|
||||||
|
MessagingControls.h Decryption.cpp \
|
||||||
|
Encryption.cpp \
|
||||||
|
GenerateKeys.cpp \
|
||||||
|
Main.cpp \
|
||||||
|
MessagingControls.cpp
|
||||||
QMAKE_TARGET = EncryptedMessaging
|
QMAKE_TARGET = EncryptedMessaging
|
||||||
DESTDIR =
|
DESTDIR =
|
||||||
TARGET = EncryptedMessaging
|
TARGET = EncryptedMessaging
|
||||||
@@ -405,8 +417,8 @@ distdir: FORCE
|
|||||||
@test -d $(DISTDIR) || mkdir -p $(DISTDIR)
|
@test -d $(DISTDIR) || mkdir -p $(DISTDIR)
|
||||||
$(COPY_FILE) --parents $(DIST) $(DISTDIR)/
|
$(COPY_FILE) --parents $(DIST) $(DISTDIR)/
|
||||||
$(COPY_FILE) --parents /usr/lib/qt/mkspecs/features/data/dummy.cpp $(DISTDIR)/
|
$(COPY_FILE) --parents /usr/lib/qt/mkspecs/features/data/dummy.cpp $(DISTDIR)/
|
||||||
$(COPY_FILE) --parents messagingcontrols.h $(DISTDIR)/
|
$(COPY_FILE) --parents Decryption.h Encryption.h GenerateKeys.h MessagingControls.h $(DISTDIR)/
|
||||||
$(COPY_FILE) --parents main.cpp messagingcontrols.cpp $(DISTDIR)/
|
$(COPY_FILE) --parents Decryption.cpp Encryption.cpp GenerateKeys.cpp Main.cpp MessagingControls.cpp $(DISTDIR)/
|
||||||
|
|
||||||
|
|
||||||
clean: compiler_clean
|
clean: compiler_clean
|
||||||
@@ -438,13 +450,13 @@ compiler_moc_predefs_clean:
|
|||||||
moc_predefs.h: /usr/lib/qt/mkspecs/features/data/dummy.cpp
|
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
|
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:
|
compiler_moc_header_clean:
|
||||||
-$(DEL_FILE) moc_messagingcontrols.cpp
|
-$(DEL_FILE) moc_MessagingControls.cpp
|
||||||
moc_messagingcontrols.cpp: messagingcontrols.h \
|
moc_MessagingControls.cpp: MessagingControls.h \
|
||||||
moc_predefs.h \
|
moc_predefs.h \
|
||||||
/usr/bin/moc
|
/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_make_all:
|
||||||
compiler_moc_source_clean:
|
compiler_moc_source_clean:
|
||||||
@@ -460,14 +472,25 @@ compiler_clean: compiler_moc_predefs_clean compiler_moc_header_clean
|
|||||||
|
|
||||||
####### Compile
|
####### Compile
|
||||||
|
|
||||||
main.o: main.cpp messagingcontrols.h
|
Decryption.o: Decryption.cpp Decryption.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
|
GenerateKeys.h
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Decryption.o Decryption.cpp
|
||||||
|
|
||||||
messagingcontrols.o: messagingcontrols.cpp messagingcontrols.h
|
Encryption.o: Encryption.cpp Encryption.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o messagingcontrols.o messagingcontrols.cpp
|
GenerateKeys.h
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Encryption.o Encryption.cpp
|
||||||
|
|
||||||
moc_messagingcontrols.o: moc_messagingcontrols.cpp
|
GenerateKeys.o: GenerateKeys.cpp GenerateKeys.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_messagingcontrols.o moc_messagingcontrols.cpp
|
$(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
|
####### Install
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#include <QtGui>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QDockWidget>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef MESSAGINGCONTROLS_H
|
||||||
|
#define MESSAGINGCONTROLS_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user