aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/test_hagelbarger.c
blob: 1e0838acb023c4e38c826496a98562a9792d5fd8 (plain)
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
#include "stdio.h"
#include "stdint.h"
#include "string.h"
#include "../common/hagelbarger.h"

int main(void)
{
	uint8_t message[9] = "JollyRog", code[20];

	printf("Message: %s\n", message);

	/* clean tail at code bit 70 and above */
	memset(code, 0, sizeof(code));

	/* encode message */
	hagelbarger_encode(message, code, 70);

	/* decode */
	hagelbarger_decode(code, message, 64);
	printf("Decoded without corruption: %s (must be the same as above)\n", message);

	/* corrupt data */
	code[0] ^= 0xfc;
	code[3] ^= 0xfc;
	code[7] ^= 0xfc;

	/* decode */
	hagelbarger_decode(code, message, 64);
	printf("Decoded with corruption: %s (must be the same as above)\n", message);

	return 0;
}