std::string TPacketCypher::DecryptPasswordString(std::string passwordstring)
{
std::stringstream ss;
std::string temppasswordstring, restoredpassword;
int hex, count = 1;
//Wenn Password gerade dann erste 2 Chars löschen ansonsten 3
if(passwordstring.length() %2 == 0)
{
passwordstring.erase(0, 2);
} else
{
passwordstring.erase(0, 3);
}
//Jeden zweiten Buchstaben zusammenfügen und anschließend nen Leerzeichen setzen
for(auto i = 1; i < passwordstring.length(); i+=2, count++)
{
temppasswordstring += passwordstring[i];
if(count %2 == 0)
{
temppasswordstring += ' ';
}
}
//Bytes in String umwandeln
ss.str(temppasswordstring);
while(ss >> std::hex >> hex)
{
restoredpassword.push_back(hex);
}
return restoredpassword;
}
//------------------------------------------------------------
std::string TPacketCypher::EncryptGamePacket(std::string str)
{
std::string encrypted_string;
int length = str.length();
int secondlength = (length / 122);
int zaehler = 0;
//Packet encrypten
for (int i = 0 ; i < length; i++)
{
if(i == (122 * zaehler))
{
if(secondlength == 0)
{
encrypted_string += abs((((length / 122) * 122) - length));
} else
{
encrypted_string += 0x7A;
secondlength--;
zaehler++;
}
}
encrypted_string += str[i] ^ 0xFF;
}
encrypted_string += (unsigned)0xFF;
return encrypted_string;
}