What are the length() functions? Pass the data size in, and use a NUL-terminated string for the password.
Code:
void XorEncode(const char *password, void *data, int size)
{
// Typecast data to a char * so the compiler knows what size it is
char *d = (char *)data;
// Start at the first character of the password
const char *p = password;
// Loop once for every byte in data
while (size--)
{
// If we reach the NUL terminator of the string, start at the beginning
if (!*p)
p = password;
// Xor the byte with the password character, then go to the
// next byte in data and the next character in the password
*d++ ^= *p++;
}
}
Bookmarks