Issue #2 added feature to generate a new default key

This commit is contained in:
amazing-username
2017-04-28 16:01:22 -05:00
parent 222f0c607b
commit e38f10e759
13 changed files with 161 additions and 144 deletions
+9 -12
View File
@@ -1,21 +1,18 @@
#include "Cryption.h"
#include"Cryption.h"
Cryption::Cryption()
{
}
{ }
Cryption::~Cryption()
{ }
Cryption::Cryption(const std::string& message)
{
this->message = message;
}
{ this->message = message; }
void Cryption::setMessage(const std::string& message)
{
this->message = message;
}
{ this->message = message; }
std::string Cryption::getMessage() const
{
return message;
}
{ return message; }
+3 -3
View File
@@ -1,15 +1,15 @@
#ifndef CRYPTION_H
#define CRYPTION_H
#include <fstream>
#include <string>
#include<fstream>
#include<string>
class Cryption
{
public:
Cryption();
~Cryption();
Cryption(const std::string&);
//void setMessage(const std::string&);
std::string getMessage() const;
protected:
+17 -34
View File
@@ -1,24 +1,24 @@
#include <iostream>
#include<iostream>
#include<sstream>
#include <ios>
#include <string>
#include<ios>
#include<string>
#include "Decryption.h"
#include "GenerateKeys.h"
#include"Decryption.h"
#include"GenerateKeys.h"
Decryption::Decryption()
{
}
{ }
Decryption::~Decryption()
{ }
Decryption::Decryption(const std::string& message)
{
this->message = message;
}
{ this->message = message; }
void Decryption::setDecryptedMessage(const std::string& message)
{
this->decryptedMessage = message;
}
{ this->decryptedMessage = message; }
void Decryption::decryptMessage()
{
GenerateKeys gk{};
@@ -31,7 +31,7 @@ void Decryption::decryptMessage()
ioEvent.close();
for (auto indexOfChar = 0; indexOfChar<messageToBeDecrypted.size(); indexOfChar+=5)
for (auto indexOfChar = 0u; indexOfChar<messageToBeDecrypted.size(); indexOfChar+=5)
{
char cryptedKey[5]{};
for (auto index = 0; index!=5; ++index)
@@ -41,36 +41,19 @@ void Decryption::decryptMessage()
}
decryptedMessage += gk.decryptedCharacters[cstringToString(cryptedKey, 5)];
}
//std::cout << "Decrypted Message: " << decryptedMessage << std::endl;
setDecryptedMessage(decryptedMessage);
}
std::string Decryption::getDecryptedMessage() const
{
return decryptedMessage;
}
{ return decryptedMessage; }
std::string Decryption::cstringToString(char tmp[], const int& SIZE)
{
std::string tmpString{};
std::stringstream cToS{};
for (auto index = 0; index!=5; ++index)
{
for (auto index = 0; index!=SIZE; ++index)
cToS << tmp[index];
}
cToS >> tmpString;
return tmpString;
}
unsigned short getTwoNumberedKey(unsigned short& number)
{
std::string wholeNumber{std::to_string(number)};
char hundred[] = {wholeNumber.at(0)};
char ten[] = {wholeNumber.at(1)};
char one[] {wholeNumber.at(2)};
unsigned short hundread, tenN, oneN;
hundread = number;
}
+4 -3
View File
@@ -1,16 +1,17 @@
#ifndef DECRYPTION_H
#define DECRYPTION_H
#include <fstream>
#include <string>
#include<fstream>
#include<string>
#include "Cryption.h"
#include"Cryption.h"
class Decryption : public Cryption
{
public:
Decryption();
~Decryption();
Decryption(const std::string&);
void setDecryptedMessage(const std::string&);
+14 -18
View File
@@ -1,30 +1,28 @@
#include <ios>
#include <iostream>
#include <string>
#include<ios>
#include<iostream>
#include<string>
#include "Encryption.h"
#include "GenerateKeys.h"
#include"Encryption.h"
#include"GenerateKeys.h"
Encryption::Encryption()
{
}
{ }
Encryption::~Encryption()
{ }
Encryption::Encryption(const std::string& message)
{
this->message = message;
}
{ this->message = message; }
void Encryption::setEncryptedMessage(const std::string& encryptedMessage)
{
this->encryptedMessage = encryptedMessage;
}
{ this->encryptedMessage = encryptedMessage; }
void Encryption::encryptMessage()
{
int numberOfNewLines{0};
auto numberOfNewLines = 0;
GenerateKeys gk{};
ioEvent.open("encryptedFile.txt", std::ios::out);
//std::cout << "String to encrypt: " << message << std::endl;
for (auto index = 0; index != message.size(); ++index)
{
char stringIndex = message.at(index);
@@ -42,6 +40,4 @@ void Encryption::encryptMessage()
std::string Encryption::getEncryptedMessage() const
{
return encryptedMessage;
}
{ return encryptedMessage; }
+4 -3
View File
@@ -1,15 +1,16 @@
#ifndef ENCRYPTION_H
#define ENCRYPTION_H
#include <fstream>
#include <string>
#include<fstream>
#include<string>
#include "Cryption.h"
#include"Cryption.h"
class Encryption : public Cryption
{
public:
Encryption();
~Encryption();
Encryption(const std::string&);
void setEncryptedMessage(const std::string&);
+26 -15
View File
@@ -1,9 +1,9 @@
#include <iostream>
#include<iostream>
#include<sstream>
#include<fstream>
#include<ios>
#include "GenerateKeys.h"
#include"GenerateKeys.h"
GenerateKeys::GenerateKeys()
{
@@ -11,23 +11,25 @@ GenerateKeys::GenerateKeys()
populateNumbers();
populateLetters();
for (auto index = 0; index!=symbols.size(); ++index)
for (auto index = 0u; index!=symbols.size(); ++index)
allCharacters.push_back(symbols[index]);
for (auto index = 0; index!=numbers.size(); ++index)
for (auto index = 0u; index!=numbers.size(); ++index)
allCharacters.push_back(numbers[index]);
for (auto index = 0; index!=letters.size(); ++index)
for (auto index = 0u; index!=letters.size(); ++index)
allCharacters.push_back(letters[index]);
populateDecryptedValues();
populateEncryptedValues();
}
GenerateKeys::~GenerateKeys()
{ }
void GenerateKeys::populateDecryptedValues()
{
std::fstream readKeys{};
readKeys.open("default_keys.txt", std::ios::in);
readKeys.open(defaultKeyFileName, std::ios::in);
std::string tmpKey{};
for (auto index = 0; index!=allCharacters.size(); ++index)
for (auto index = 0u; index!=allCharacters.size(); ++index)
{
readKeys >> tmpKey;
decryptedCharacters[tmpKey] = static_cast<char>(allCharacters[index]);
@@ -40,9 +42,9 @@ void GenerateKeys::populateDecryptedValues()
void GenerateKeys::populateEncryptedValues()
{
std::fstream readKeys{};
readKeys.open("default_keys.txt", std::ios::in);
readKeys.open(defaultKeyFileName, std::ios::in);
std::string tmpKey{};
for (auto index = 0; index!=allCharacters.size(); ++index)
for (auto index = 0u; index!=allCharacters.size(); ++index)
{
readKeys >> tmpKey;
encryptedCharacters[decryptedCharacters[tmpKey]] = tmpKey;
@@ -99,21 +101,26 @@ void GenerateKeys::generateKey(std::string& key, const int& SIZE)
}
void GenerateKeys::keyMove()
{
std::string tmpKey{};
for (auto index = 0; index!=totalCharacters; ++index)
{
std::string tmpKey{};
generateKey(tmpKey, keySize);
keys.push_back(tmpKey);
tmpKey = "";
}
if (isThereRepetition())
{
keys.clear();
keyMove();
}
std::cout << "No repetitions in keys" << std::endl;
}
void GenerateKeys::print(const std::vector<int>& ch)
{
for (auto index = 0; index!=ch.size(); ++index)
for (auto index = 0u; index!=ch.size(); ++index)
std::cout << ch[index] << " ";
std::cout << std::endl;
}
void GenerateKeys::checkRepetition()
bool GenerateKeys::isThereRepetition()
{
for (auto index = 0; index!=totalCharacters; ++index)
{
@@ -125,14 +132,18 @@ void GenerateKeys::checkRepetition()
++repetition;
}
if (repetition > 1)
{
std::cout << "Too much repetitive stuff" << std::endl;
return true;
}
}
return false;
}
void GenerateKeys::keyDump()
{
std::fstream dump{};
dump.open("default_keys.txt", std::ios::out);
for (auto index = 0; index!=keys.size(); ++index)
dump.open(defaultKeyFileName, std::ios::out);
for (auto index = 0u; index!=keys.size(); ++index)
dump << keys[index] << '\n';
dump.close();
}
+7 -7
View File
@@ -8,9 +8,8 @@
class GenerateKeys
{
public:
typedef unsigned short unsignedShort;
GenerateKeys();
~GenerateKeys();
void populateDecryptedValues();
void populateEncryptedValues();
@@ -29,20 +28,21 @@ private:
void addRange(std::vector<int>&, int, const int);
void generateKey(std::string&, const int&);
void checkRepetition();
bool isThereRepetition();
void print(const std::vector<int>&);
char getChar(std::vector<int>&);
std::vector<std::string> keys{};
std::vector<int> symbols{};
std::vector<int> numbers{};
std::vector<int> letters{};
std::vector<int> allCharacters{};
std::vector<int> symbols;
std::vector<int> numbers;
std::vector<int> letters;
std::vector<int> allCharacters;
std::map<char, std::string> encryptedCharacters{};
std::map<std::string, char> decryptedCharacters{};
std::string defaultKeyFileName{"default_keys.txt"};
//KeySize show equal the value in key
const int keySize{5};
const int totalCharacters{63};
+41 -23
View File
@@ -1,31 +1,36 @@
#include "KeyManagementWindow.h"
#include "GenerateKeys.h"
#include"KeyManagementWindow.h"
#include"GenerateKeys.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QString>
#include <string>
#include<QtWidgets>
#include<QString>
#include<QWidget>
#include<string>
#include<sstream>
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <ios>
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<ios>
KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent)
{
GenerateKeys gk;
GenerateKeys gk{};
comboBoxOfKeys = new QComboBox;
valueOfKey = new QLineEdit;
comboBoxOfKeys = new QComboBox{};
valueOfKey = new QLineEdit{};
generateNewDefaultKeys = new QPushButton(tr("Generate New Default Key"));
QVBoxLayout* vBox = new QVBoxLayout;
QHBoxLayout* hBox = new QHBoxLayout;
vBox = new QVBoxLayout;
hBox = new QHBoxLayout;
QHBoxLayout* hBox2 = new QHBoxLayout;
setContentsOfComboBox();
hBox->addWidget(comboBoxOfKeys);
hBox->addWidget(valueOfKey);
hBox2->addWidget(generateNewDefaultKeys);
vBox->addLayout(hBox);
vBox->addLayout(hBox2);
setLayout(vBox);
@@ -35,6 +40,15 @@ KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent)
setWindowTitle("Key Management Window");
QObject::connect(comboBoxOfKeys, SIGNAL(currentIndexChanged(int)), SLOT(test()));
QObject::connect(generateNewDefaultKeys, SIGNAL(clicked()), this, SLOT(generation()));
}
KeyManagementWindow::~KeyManagementWindow()
{
delete comboBoxOfKeys;
delete valueOfKey;
delete generateNewDefaultKeys;
delete hBox;
delete vBox;
}
@@ -42,8 +56,7 @@ void KeyManagementWindow::setContentsOfComboBox()
{
GenerateKeys gk;
std::cout << "got here" << std::endl;
for (auto index = 0; index!=gk.allCharacters.size(); ++index)
for (auto index = 0u; index!=gk.allCharacters.size(); ++index)
{
std::string ch{static_cast<char>(gk.allCharacters[index])};
QString bl = QString::fromStdString(ch);
@@ -52,17 +65,22 @@ void KeyManagementWindow::setContentsOfComboBox()
}
void KeyManagementWindow::test()
{
GenerateKeys gk;
QString bo = comboBoxOfKeys->currentText();
std::string k = bo.toStdString();
char f;
GenerateKeys gk{};
QString bo{comboBoxOfKeys->currentText()};
std::string k{bo.toStdString()};
char f{};
std::stringstream lazy{};
lazy << k;
lazy >> f;
//std::cout << "character: " << f << std::endl;
std::string value{gk.encryptedCharacters[f]};
QString v = QString::fromStdString(value);
QString v{QString::fromStdString(value)};
valueOfKey->setText(v);
}
void KeyManagementWindow::generation()
{
GenerateKeys gk{};
gk.keyMove();
gk.keyDump();
}
+15 -5
View File
@@ -1,25 +1,35 @@
#ifndef KEYMANAGEMENTWINDOW_H
#define KEYMANAGEMENTWINDOW_H
#include <QDialog>
#include <QComboBox>
#include <QLineEdit>
#include<QDialog>
#include<QVBoxLayout>
#include<QHBoxLayout>
#include<QComboBox>
#include<QLineEdit>
class QHBoxLayout;
class QVBoxLayout;
class QComboBox;
class QLineEdit;
class QPushButton;
class KeyManagementWindow : public QDialog
{
Q_OBJECT
public:
KeyManagementWindow(QWidget* parent = 0);
~KeyManagementWindow();
void setContentsOfComboBox();
private slots:
void test();
void generation();
private:
QComboBox* comboBoxOfKeys;
QLineEdit* valueOfKey;
QHBoxLayout* hBox{};
QVBoxLayout* vBox{};
QComboBox* comboBoxOfKeys{};
QLineEdit* valueOfKey{};
QPushButton* generateNewDefaultKeys;
};
#endif
+2 -2
View File
@@ -1,6 +1,6 @@
#include <QApplication>
#include<QApplication>
#include "MessagingControls.h"
#include"MessagingControls.h"
int main(int argc, char* argv[])
{
+7 -7
View File
@@ -1,11 +1,11 @@
#include <QtGui>
#include <QString>
#include <QIcon>
#include <iostream>
#include<QtGui>
#include<QString>
#include<QIcon>
#include<iostream>
#include "MessagingControls.h"
#include "KeyManagementWindow.h"
#include "Encryption.h"
#include"MessagingControls.h"
#include"KeyManagementWindow.h"
#include"Encryption.h"
#include"Decryption.h"
MessagingControls::MessagingControls()
+12 -12
View File
@@ -1,18 +1,18 @@
#ifndef MESSAGINGCONTROLS_H
#define MESSAGINGCONTROLS_H
#include <QDialog>
#include <QPushButton>
#include <QLineEdit>
#include <QTextEdit>
#include <QLabel>
#include <QMenuBar>
#include <QMainWindow>
#include <QMenu>
#include <QAction>
#include <QVBoxLayout>
#include <QDockWidget>
#include <QWidget>
#include<QDialog>
#include<QPushButton>
#include<QLineEdit>
#include<QTextEdit>
#include<QLabel>
#include<QMenuBar>
#include<QMainWindow>
#include<QMenu>
#include<QAction>
#include<QVBoxLayout>
#include<QDockWidget>
#include<QWidget>
#include<QString>
class QLabel;