forked from mgrone/stream1090
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_gen.cpp
More file actions
125 lines (105 loc) · 3.4 KB
/
Copy pathtable_gen.cpp
File metadata and controls
125 lines (105 loc) · 3.4 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright 2025 Martin Gronemann
*
* This file is part of stream1090 and is licensed under the GNU General
* Public License v3.0. See the top-level LICENSE file for details.
*/
#include <iostream>
#include <vector>
#include "CRC.hpp"
#include "Sampler.hpp"
using namespace CRC;
int hashFunction(crc_t crc, int N) {
return (crc % N);
}
void generateKeySetExtSquitter(std::vector<crc_t>& keys) {
// skip the first 5 bits (df), first do all one bit corrections
for (int i = 0; i < 112-5; i++) {
keys.push_back(compute(encodeFixOp(0x1,i)));
}
// now two bit bursts
for (int i = 0; i < 111-5; i++) {
keys.push_back(compute(encodeFixOp(0x3,i)));
}
// this seems to help, for the parity block
for (int i = 0; i < 16; i++) {
keys.push_back(compute(encodeFixOp(129,i)));
}
}
void generateKeySetExtSquitterBurst(std::vector<crc_t>& keys) {
// skip the first 5 bits (df), first do all one bit corrections
for (int i = 0; i < 112-5; i++) {
keys.push_back(compute(encodeFixOp(0x1,i)));
}
// now two bit bursts (11)
for (int i = 0; i < 111-5; i++) {
keys.push_back(compute(encodeFixOp(0x3,i)));
}
// now three bit bursts (111)
for (int i = 0; i < 110-5; i++) {
keys.push_back(compute(encodeFixOp(0x7,i)));
}
// this seems to help, for the parity block
for (int i = 0; i < 16; i++) {
keys.push_back(compute(encodeFixOp(129,i)));
}
}
void generateKeySetShort1Bit(std::vector<crc_t>& keys) {
for (int i = 0; i < 56-5; i++) {
keys.push_back(compute(encodeFixOp(0x1,i)));
}
}
void generateKeySetShort2Bit(std::vector<crc_t>& keys) {
for (int i = 0; i < 56-5; i++) {
keys.push_back(compute(encodeFixOp(0x1,i)));
}
for (int i = 0; i < 55-5; i++) {
keys.push_back(compute(encodeFixOp(0x3,i)));
}
}
int testTableSize(const std::vector<crc_t>& keys, int tableSize) {
std::vector<int> collisions(tableSize, 0);
int maxCollisions = 0;
for (auto k : keys) {
auto index = hashFunction(k, tableSize);
collisions[index]++;
maxCollisions = std::max(collisions[index], maxCollisions);
}
return maxCollisions;
}
int bruteforceMinTableSize(const std::vector<crc_t>& keys) {
for (int N = keys.size(); N < 6000; N++) {
int res = testTableSize(keys, N);
if (res == 1) {
return N;
}
}
return 0;
}
int runExtSquitter() {
std::vector<crc_t> keys;
generateKeySetExtSquitter(keys);
return bruteforceMinTableSize(keys);
}
int runExtSquitterBurst() {
std::vector<crc_t> keys;
generateKeySetExtSquitterBurst(keys);
return bruteforceMinTableSize(keys);
}
int runOneBitShort() {
std::vector<crc_t> keys;
generateKeySetShort1Bit(keys);
return bruteforceMinTableSize(keys);
}
int runTwoBitShort() {
std::vector<crc_t> keys;
generateKeySetShort2Bit(keys);
return bruteforceMinTableSize(keys);
}
int main(/*int argc, char** argv*/) {
std::cout << "DF17 min table size: " << runExtSquitter() << std::endl;
std::cout << "DF17 min table size with advanced correction: " << runExtSquitterBurst() << std::endl;
std::cout << "DF11 one bit short message min table size: " << runOneBitShort() << std::endl;
std::cout << "DF11 one bit short message min table size: " << runTwoBitShort() << std::endl;
return 0;
}