Changed from ASCII cryption to key Cryption

This commit is contained in:
monde
2017-04-25 13:05:01 -05:00
parent c82d81fdc1
commit fbee689234
12 changed files with 1700 additions and 329 deletions
+24 -33
View File
@@ -1,4 +1,5 @@
#include <iostream>
#include<sstream>
#include <ios>
#include <string>
@@ -7,7 +8,6 @@
Decryption::Decryption()
{
}
Decryption::Decryption(const std::string& message)
{
@@ -21,55 +21,46 @@ void Decryption::setDecryptedMessage(const std::string& message)
}
void Decryption::decryptMessage()
{
GenerateKeys gk;
GenerateKeys gk{};
ioEvent.open("encryptedFile.txt", std::ios::in);
std::string messageToBeDecrypted, decryptedMessage;
std::string messageToBeDecrypted{}, decryptedMessage{};
while(!ioEvent.eof())
{
ioEvent >> messageToBeDecrypted;
}
while(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++)
for (auto indexOfChar = 0; indexOfChar<messageToBeDecrypted.size(); indexOfChar+=5)
{
if ((index + encryptedTwoKey) < messageToBeDecrypted.size())
char cryptedKey[5]{};
for (auto index = 0; index!=5; ++index)
{
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;
}
cryptedKey[index] = (messageToBeDecrypted.at(indexOfChar + index));
}
decryptedMessage += gk.decryptedCharacters[cstringToString(cryptedKey, 5)];
}
//std::cout << "Decrypted Message: " << decryptedMessage << std::endl;
setDecryptedMessage(decryptedMessage);
}
std::string Decryption::getDecryptedMessage() const
{
return decryptedMessage;
}
std::string Decryption::cstringToString(char tmp[], const int& SIZE)
{
std::string tmpString{};
std::stringstream cToS{};
for (auto index = 0; index!=5; ++index)
{
cToS << tmp[index];
}
cToS >> tmpString;
return tmpString;
}
unsigned short getTwoNumberedKey(unsigned short& number)
@@ -80,6 +71,6 @@ unsigned short getTwoNumberedKey(unsigned short& number)
char one[] {wholeNumber.at(2)};
unsigned short hundread, ten, one;
hundread = number.at()
unsigned short hundread, tenN, oneN;
hundread = number;
}