phython to C++

Posts 1–3 of 3 · Page 1 of 1
phython to C++
Anyone got any suggestions in converting this Xor code into C++.

Code:
def xor(string, with_byte=0xFF, skip_bytes=4):
    xored = string[0:skip_bytes]
    for byte in string[skip_bytes:]:
        xored += chr(ord(byte) ^ with_byte)
    return xored
You might want to learn C++ first.

Really, that's really easy to translate to C++ if you know C++. Really.
Code:
xor(str string, char with_byte = 0xFF, int skip_bytes = 4)
{
string xored = str.supstr(skip_byte);
for(int i = 0; str[i + skip_bytes]; i++)xored[i] = (str[i +skip_bytes] ^ with_byte);
return xored;
}
I believe something like this, though python must have some fundamental differences from C++ because returning xored like this would cause errors since the string is declare on the stack. Also I'm not quite sure what this line does, so I made it up.
Code:
xored += chr(ord(byte) ^ with_byte)
In C++ this would append the byte to the end of the string, but I don't think that's what the author wants to do so I changed it, idk how the operation works in python. TBH though your better of writing this from scratch in C++, and there are plenty of examples mind u of C++ xor functions.
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us