-
Notifications
You must be signed in to change notification settings - Fork 0
/
xor_buffers.c
36 lines (28 loc) · 1 KB
/
xor_buffers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "xor_buffers.h"
#include "utility.h"
void xor_buffers(const char *buffer1, const char *buffer2, char *out_buffer, size_t len)
{
for (int i = 0; i < len; i++) {
out_buffer[i] = buffer1[i] ^ buffer2[i];
}
}
#ifdef XOR_BUFFER_TEST
int main(void)
{
char buffer1[] = { 0x1c, 0x01, 0x11, 0x00, 0x1f, 0x01, 0x01, 0x00, 0x06, 0x1a, 0x02, 0x4b, 0x53, 0x53, 0x50, 0x09, 0x18, 0x1c };
char buffer2[] = { 0x68, 0x69, 0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x75, 0x6c, 0x6c, 0x27, 0x73, 0x20, 0x65, 0x79, 0x65 };
char expected_result[] = { 0x74, 0x68, 0x65, 0x20, 0x6b, 0x69, 0x64, 0x20, 0x64, 0x6f, 0x6e, 0x27, 0x74, 0x20, 0x70, 0x6c, 0x61, 0x79 };
char result[sizeof(expected_result)];
xor_buffers(buffer1, buffer2, result, sizeof(buffer1));
if (memcmp(result, expected_result, sizeof(expected_result)) == 0) {
print_success("xor_buffers OK");
} else {
print_fail("xor_buffers failed");
exit(-1);
}
return 0;
}
#endif // XOR_BUFFER_TEST