First of all, your algorithm doesn't do what you probably think it does. You end up xoring every byte of Buffer
with every byte of Key
, which really means that you're xoring every byte of Buffer
with the same byte. What you probably meant was something like this:
const unsigned char Key[1024] = {0x.........};
void EncodeBuffer(unsigned char Buffer[],unsigned int Size) {
unsigned int i = 0;
while (i < Size) {
//Each byte of the buffer is xor'd with a byte of the key
//Each byte of the key may be used for more than one byte in the buffer (insecure)
Buffer[i] ^= Key[i % 1024];
i++;
}
}
Now, this is a bit more secure, but not secure enough for the real world. The more you encrypt with this, the easier it will be for attackers to guess the key. Additionally, if the attacker can see the source code (or even the compiled binary), they will have the key.
What you're likely looking for is a one-time pad, which requires a key at least the length of the input.
By the way, if you're trying to write this to use in any sort of real-world situation, I suggest you don't and just use an existing encryption library. This stuff is hard to get right, and there are enough people working on this that it's better to save yourself (not to mention your customers) the headaches of dealing with buggy encryption.