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
PasswordEncryption/Decryption.cpp
T
amazing-username 6c1f92ea30 Refractoring
2017-06-23 18:01:42 -05:00

69 lines
1.6 KiB
C++

#include<iostream>
#include<fstream>
#include<sstream>
#include<ios>
#include<vector>
#include"Decryption.h"
#include"KeyRetrieval.h"
Decryption::Decryption(const std::string& message)
{
this->message = message;
setupMap();
decryptMessage();
}
void Decryption::setDecryptedMessage(const std::string& message)
{ this->decryptedMessage = message; }
void Decryption::setMessage(const std::string& message)
{ this->message = message; }
void Decryption::decryptMessage()
{
std::fstream ioEvent{};
ioEvent.open("encryptedFile.txt", std::ios::in);
std::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!=5; ++index)
cryptedKey[index] = (messageToBeDecrypted.at(indexOfChar + index));
decryptedMessage += decryptedCharacters[cstringToString(cryptedKey, 5)];
}
setDecryptedMessage(decryptedMessage);
}
std::string Decryption::getDecryptedMessage() const
{ return decryptedMessage; }
std::string Decryption::getMessage() const
{ return message; }
void Decryption::setupMap()
{
KeyRetrieval kr{};
std::vector<std::string> k{kr.keyStructure()};
std::vector<int> c{kr.codeCharacterStructure()};
for (auto index = 0; index!=c.size(); ++index)
decryptedCharacters[k[index]] = c[index];
}
std::string Decryption::cstringToString(char tmp[], const int& SIZE)
{
std::string tmpString{};
std::stringstream cToS{};
for (auto index = 0; index!=SIZE; ++index)
cToS << tmp[index];
cToS >> tmpString;
return tmpString;
}