I have a problem, with this and I wanted to know if any of you could fix it will be very appreciated!
I am trying to encrypt a message to send to people in my game
Problem: When I try to send my message the 1st time gonna works and show the text on Letter and the second time is gonna show the encrypted text and I don't want people see that
("ZFDKWEK,CSJ,$MS(,,,)")
if (MessageEnc)
{
if (GET_GAME_TIMER() >= destroy_tick2){
destroy_tick2 = GET_GAME_TIMER() + 82000;
int i = 0;
for (i = 0;i<18;i++)
{
if (i == PlayerId()) continue;
int Handle = GetPlayerHandle(i);
if(!DoesEntityExist(Handle)) continue;
char key = 'j'; //Key
char *encMess = "ZFDKWEK,CSJ,$MS(,,,)";
for (int i = 0; i < strlen(encMess); i++)
{
encMess[i] ^= key;
}
char buf[64];
snprintf(buf, sizeof(buf), "~r~%s", encMess);
NETWORK::NETWORK_HANDLE_FROM_PLAYER(i, &networkHandle, 13);
NETWORK::NETWORK_SEND_TEXT_MESSAGE(buf, &networkHandle);
printf(encMess);
}
}
}
Your XOR operation is encrypting the static string literal on every odd iteration and then decrypting it on ever even iteration. Use a tmp buffer to avoid modifying the string literal. I don't recall the rules, but I think that attempting to modify the memory contents of a string literal is entering undefined behavior territory. So it's best to avoid this type of coding to begin with.
Change this set of code:
To this: