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 c82d81fdc1 Working on Issue #5
2017-04-13 11:48:28 -05:00

86 lines
1.9 KiB
C++

#include <iostream>
#include <ios>
#include <string>
#include "Decryption.h"
#include "GenerateKeys.h"
Decryption::Decryption()
{
}
Decryption::Decryption(const std::string& message)
{
this->message = message;
}
void Decryption::setDecryptedMessage(const std::string& message)
{
this->decryptedMessage = message;
}
void Decryption::decryptMessage()
{
GenerateKeys gk;
ioEvent.open("encryptedFile.txt", std::ios::in);
std::string messageToBeDecrypted, decryptedMessage;
while(!ioEvent.eof())
{
ioEvent >> messageToBeDecrypted;
}
ioEvent.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];
index += 1;
}
else
{
decryptedMessage += gk.decryptedCharacters[number];
index += 2;
}
}
}
setDecryptedMessage(decryptedMessage);
}
std::string Decryption::getDecryptedMessage() const
{
return decryptedMessage;
}
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, ten, one;
hundread = number.at()
}