Issue #2 added feature to generate a new default key
This commit is contained in:
+8
-11
@@ -1,21 +1,18 @@
|
||||
#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; }
|
||||
|
||||
+1
-1
@@ -8,8 +8,8 @@ class Cryption
|
||||
{
|
||||
public:
|
||||
Cryption();
|
||||
~Cryption();
|
||||
Cryption(const std::string&);
|
||||
//void setMessage(const std::string&);
|
||||
|
||||
std::string getMessage() const;
|
||||
protected:
|
||||
|
||||
+12
-29
@@ -7,18 +7,18 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class Decryption : public Cryption
|
||||
public:
|
||||
|
||||
Decryption();
|
||||
~Decryption();
|
||||
Decryption(const std::string&);
|
||||
|
||||
void setDecryptedMessage(const std::string&);
|
||||
|
||||
+9
-13
@@ -6,25 +6,23 @@
|
||||
#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; }
|
||||
|
||||
@@ -10,6 +10,7 @@ class Encryption : public Cryption
|
||||
{
|
||||
public:
|
||||
Encryption();
|
||||
~Encryption();
|
||||
Encryption(const std::string&);
|
||||
|
||||
void setEncryptedMessage(const std::string&);
|
||||
|
||||
+24
-13
@@ -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
@@ -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};
|
||||
|
||||
+33
-15
@@ -1,9 +1,9 @@
|
||||
#include"KeyManagementWindow.h"
|
||||
#include"GenerateKeys.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include<QtWidgets>
|
||||
#include<QString>
|
||||
#include<QWidget>
|
||||
#include<string>
|
||||
#include<sstream>
|
||||
#include<iostream>
|
||||
@@ -13,19 +13,24 @@
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
+12
-2
@@ -2,24 +2,34 @@
|
||||
#define KEYMANAGEMENTWINDOW_H
|
||||
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user