2020-全国工业互联网安全技术技能大赛
5G
考查polar编码
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
| sub_401FD0(); v3 = time(0); srand(v3); memset(&v32, 0, 0x80u); v30 = (char *)malloc(dword_40F040 + 1); sub_40E540("%64s", &v32); v26 = (signed int)(double)sub_4029B0((long double)dword_40F040); v29 = dword_40F040; v4 = 4 * (dword_40F040 / 2); v31 = dword_40F040 / 2; v5 = malloc(4 * (dword_40F040 / 2)); v28 = malloc(v4); memcpy(v5, &dword_40F080, v4); memcpy(v28, (char *)&dword_40F080 + v4, v4); v6 = 0; v27 = malloc(4 * v29); memset(v27, 0, 4 * v29); v7 = v30; do { LOBYTE(v8) = *((_BYTE *)&v32 + v6); v9 = 0; do { v10 = v8 & 1; v8 = (unsigned int)(char)v8 >> 1; v7[v9++] = v10; } while ( v9 != 8 ); ++v6; v7 += 8; } while ( v6 != 64 );
|
main函数开始先输入64个字符,然后转换成比特,共512位,进行编码和传输,题目中给了输出可以根据输出进行解码求输入,解码部分根据提示利用开源代码https://github.com/albusSimba/pyPolar实现,但是解码出来的数据位数是1024位,在编码最开始赋值的时候还有一个类似于换表的操作,将512位数据打乱写入1024位的矩阵中,所以解码的时候还需要提取出输入的512位,才可以得到最终结果
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
| from QueryPerformanceCounter import * from polarcodes5G import * n = 1024 k = n // 2 performance_counter = QueryPerformanceCounter() myPC = Construct(n, k) s = "-1.756208 1.027628 -0.952465 -1.638855 -1.462390 0.208588 0.591268 -0.179454 1.095095 0.447900 0.947692 1.350273 -1.155633 -1.938154 0.046054 1.175568 -0.007052 1.220866 1.890119 1.539061 0.677526 -0.493938 1.113000 1.148966 0.437962 -1.025365 -1.001201 -0.274902 0.545109 -1.125495 -1.112381 0.214771 0.635569 …………" t = [float(i) for i in s.split(" ")] myPC.llrs = np.array(t) performance_counter.start() Decoder(myPC) performance_counter.end("Decoder") res = list(myPC.message_received) bits = list(myPC.msg_bits) f = [0] * 512 for i, c in enumerate(bits): f[i] = res[c] for i in range(0, 512, 8): ch = 0 for j in range(8): ch += (f[i + j] << j) & 0xff print(chr(ch), end="")
|
Comments