This repository has been archived on 2026-07-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
amazing-username 30bc1f8245 Addressed Issue #10
2018-03-31 15:04:20 -05:00

63 lines
1.5 KiB
C++

#include<fstream>
#include<ios>
#include<vector>
#include"Conversions.h"
#include"Decryption.h"
#include"KeyRetrieval.h"
Decryption::Decryption(const string& message)
{
this->message = message;
decryptMessage();
}
Decryption::Decryption(const Password<>& py, const Key<>& ky)
{
setupMap(ky);
passwordPath.assign(py.passwordPath());
decryptMessage();
}
void Decryption::setDecryptedMessage(const string& message) { this->decryptedMessage = message; }
void Decryption::setMessage(const string& message) { this->message = message; }
void Decryption::retrieveMetaData()
{
}
void Decryption::decryptMessage()
{
fstream ioEvent{};
ioEvent.open(passwordPath.c_str(), std::ios::in);
string messageToBeDecrypted{}, decryptedMessage{};
while(ioEvent >> messageToBeDecrypted);
ioEvent.close();
for (auto indexOfChar = 0u; indexOfChar<messageToBeDecrypted.size(); indexOfChar+=5)
{
char cryptedKey[5]{};
for (auto index = 0; index!=keyLength; ++index)
cryptedKey[index] = (messageToBeDecrypted.at(indexOfChar + index));
Conversions cnvert;
decryptedMessage += decryptedCharacters[cnvert.cstringToString(cryptedKey, 5)];
}
setDecryptedMessage(decryptedMessage);
}
string Decryption::getDecryptedMessage() const { return decryptedMessage; }
string Decryption::getMessage() const { return message; }
void Decryption::setupMap(const Key<>& ky)
{
KeyRetrieval kr{ky};
vector<string> k{kr.keyStructure()};
vector<int> c{kr.codeCharacterStructure()};
for (auto index = 0u; index!=c.size(); ++index)
decryptedCharacters[k[index]] = c[index];
}