XOR on string's characters

Hi guys,
I’m trying to implement HMAC MD5 and in the implementation I need to XOR the characters of two strings. Since I need to get same results on both PHP and C++, I’m trying to XOR the ASCII values of each character. Any advice on how to do that?


using the XOR (^) operator?

I’m not familiar with this speciifc case but having been bitten by similar issues then I guess it would be important to check what units are iterated for each atomic XOR operation. Is it at the byte level or the character level? (Which may not be 8-bits per character if the string isn’t pure ASCII.) Although I now realise that the OP specified ASCii in the question :slight_smile:

You probably already do this, but make sure you’re talking about char arrays (preferably unsigned char), and not std::string or String. Using XOR can turn off all the bits on a char, and it will then be the null terminator of a C++ string, so that any operation on it (such as copying, comparing, etc.) will stop at that null terminator.

Thanks guys. I’m working mainly with Strings and that’s why I’m struggling. I guess I should try getting the raw UTF8 pointer from a String and see if that works.