-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandomizer.c
More file actions
87 lines (73 loc) · 3.31 KB
/
randomizer.c
File metadata and controls
87 lines (73 loc) · 3.31 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "numerology.h"
#include "randomizer.h"
#if 0
static uint8_t old_randomization_sequence[OVP_SINGLE_FRAME_SIZE] = {
163, 129, 92, 196, 201, 8, 14, 83, 204, 161,
251, 41, 158, 79, 22, 224, 151, 78, 43, 87,
18, 167, 63, 194, 77, 107, 15, 8, 48, 70,
17, 86, 13, 26, 19, 231, 80, 151, 97, 243,
190, 227, 153, 176, 100, 57, 34, 44, 240, 9,
225, 134, 207, 115, 89, 194, 92, 142, 227, 215,
63, 112, 212, 39, 194, 224, 129, 146, 218, 252,
202, 90, 128, 66, 131, 21, 15, 162, 158, 21,
156, 139, 219, 164, 70, 28, 16, 159, 179, 71,
108, 94, 21, 18, 31, 173, 56, 61, 3, 186,
144, 141, 190, 211, 101, 35, 50, 184, 171, 16,
98, 126, 198, 38, 124, 19, 201, 101, 61, 21,
21, 237, 53, 244, 87, 245, 88, 17, 157, 142,
232, 52, 201, 89
};
#endif // 0
#if 0
// Python code to generate the CCSDS randomization sequence
// as defined in CCSDS 101.0-B-3, h(x) = x^8 + x^7 + x^5 + x^3 + 1
//
// lfsr = 0xff
// for byte_index in range(0,134):
// value = 0
// for bit_index in range(0,8):
// value = (value << 1) | (lfsr & 0x01)
// feedback = bool(lfsr & 0x01) ^ bool(lfsr & 0x08) ^ bool(lfsr & 0x20) ^ bool(lfsr & 0x80)
// lfsr = (lfsr >> 1) & 0x7f
// if feedback:
// lfsr = lfsr | 0x80
// print(f"0x{value:02x}, ", end="")
static uint8_t ccsds_101_0_b_3_randomization_sequence[OVP_SINGLE_FRAME_SIZE] = {
0xff, 0x48, 0x0e, 0xc0, 0x9a, 0x0d, 0x70, 0xbc, 0x8e, 0x2c,
0x93, 0xad, 0xa7, 0xb7, 0x46, 0xce, 0x5a, 0x97, 0x7d, 0xcc,
0x32, 0xa2, 0xbf, 0x3e, 0x0a, 0x10, 0xf1, 0x88, 0x94, 0xcd,
0xea, 0xb1, 0xfe, 0x90, 0x1d, 0x81, 0x34, 0x1a, 0xe1, 0x79,
0x1c, 0x59, 0x27, 0x5b, 0x4f, 0x6e, 0x8d, 0x9c, 0xb5, 0x2e,
0xfb, 0x98, 0x65, 0x45, 0x7e, 0x7c, 0x14, 0x21, 0xe3, 0x11,
0x29, 0x9b, 0xd5, 0x63, 0xfd, 0x20, 0x3b, 0x02, 0x68, 0x35,
0xc2, 0xf2, 0x38, 0xb2, 0x4e, 0xb6, 0x9e, 0xdd, 0x1b, 0x39,
0x6a, 0x5d, 0xf7, 0x30, 0xca, 0x8a, 0xfc, 0xf8, 0x28, 0x43,
0xc6, 0x22, 0x53, 0x37, 0xaa, 0xc7, 0xfa, 0x40, 0x76, 0x04,
0xd0, 0x6b, 0x85, 0xe4, 0x71, 0x64, 0x9d, 0x6d, 0x3d, 0xba,
0x36, 0x72, 0xd4, 0xbb, 0xee, 0x61, 0x95, 0x15, 0xf9, 0xf0,
0x50, 0x87, 0x8c, 0x44, 0xa6, 0x6f, 0x55, 0x8f, 0xf4, 0x80,
0xec, 0x09, 0xa0, 0xd7
};
#endif // 0
static uint8_t ovp_randomization_sequence[OVP_SINGLE_FRAME_SIZE] = {
0xff, 0x1a, 0xaf, 0x66, 0x52, 0x23, 0x1e, 0x10, 0xa0, 0xf9,
0xfa, 0x8a, 0x98, 0x67, 0x7d, 0xd2, 0xb4, 0xe6, 0xc5, 0xdb,
0xcb, 0x6b, 0x92, 0x68, 0xe2, 0x7a, 0x1d, 0x60, 0xb2, 0x06,
0xe0, 0x25, 0xfe, 0x35, 0x5e, 0xcc, 0xa4, 0x46, 0x3c, 0x21,
0x41, 0xf3, 0xf5, 0x15, 0x30, 0xce, 0xfb, 0xa5, 0x69, 0xcd,
0x8b, 0xb7, 0x96, 0xd7, 0x24, 0xd1, 0xc4, 0xf4, 0x3a, 0xc1,
0x64, 0x0d, 0xc0, 0x4b, 0xfc, 0x6a, 0xbd, 0x99, 0x48, 0x8c,
0x78, 0x42, 0x83, 0xe7, 0xea, 0x2a, 0x61, 0x9d, 0xf7, 0x4a,
0xd3, 0x9b, 0x17, 0x6f, 0x2d, 0xae, 0x49, 0xa3, 0x89, 0xe8,
0x75, 0x82, 0xc8, 0x1b, 0x80, 0x97, 0xf8, 0xd5, 0x7b, 0x32,
0x91, 0x18, 0xf0, 0x85, 0x07, 0xcf, 0xd4, 0x54, 0xc3, 0x3b,
0xee, 0x95, 0xa7, 0x36, 0x2e, 0xde, 0x5b, 0x5c, 0x93, 0x47,
0x13, 0xd0, 0xeb, 0x05, 0x90, 0x37, 0x01, 0x2f, 0xf1, 0xaa,
0xf6, 0x65, 0x22, 0x31
};
// apply or remove randomization, in place, to reduce spectral features of the data
void randomize_ovp_frame(uint8_t *buf) {
for (int i=0; i < OVP_SINGLE_FRAME_SIZE; i++) {
buf[i] ^= ovp_randomization_sequence[i];
}
}