From ef152cc53f98922466627ad728a89c066cd4de80 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sun, 18 Jul 2021 04:48:32 +0200 Subject: [PATCH] scramble user data only using Xorshift32 --- decode.cc | 13 ++++++------- encode.cc | 15 +++++++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/decode.cc b/decode.cc index 296de66..eac1533 100644 --- a/decode.cc +++ b/decode.cc @@ -11,6 +11,7 @@ Copyright 2021 Ahmet Inan namespace DSP { using std::abs; using std::min; using std::cos; using std::sin; } #include "bip_buffer.hh" #include "resampler.hh" +#include "xorshift.hh" #include "trigger.hh" #include "complex.hh" #include "decibel.hh" @@ -173,8 +174,6 @@ struct Decoder static const int mls1_len = 255; static const int mls1_off = - mls1_len / 2; static const int mls1_poly = 0b100101011; - static const int mls3_poly = 0b10001000000001011; - static const int mls4_poly = 0b10111010010000001; static const int buffer_len = (rows_max + 8) * (symbol_len + guard_len); static const int search_pos = buffer_len - 4 * (symbol_len + guard_len); DSP::ReadPCM *pcm; @@ -422,17 +421,14 @@ struct Decoder for (int i = 0; i < buffer_len; ++i) tdom[i] = resam[i] * osc(); - CODE::MLS seq3(mls3_poly), seq4(mls4_poly); cmplx *cur = tdom + symbol_pos - (code_rows + 1) * (symbol_len + guard_len); fwd(fdom, cur); for (int j = 0; j < code_rows; ++j) { for (int i = 0; i < code_cols; ++i) head[bin(i+code_off)] = fdom[bin(i+code_off)]; fwd(fdom, cur += symbol_len+guard_len); - for (int i = 0; i < code_cols; ++i) { - cmplx con = fdom[bin(i+code_off)] / head[bin(i+code_off)]; - cons[code_cols*j+i] = cmplx(con.real() * nrz(seq3()), con.imag() * nrz(seq4())); - } + for (int i = 0; i < code_cols; ++i) + cons[code_cols*j+i] = fdom[bin(i+code_off)] / head[bin(i+code_off)]; } value precision = 16; if (1) { @@ -553,6 +549,9 @@ int main(int argc, char **argv) return 1; } const int data_len = code_len - (12 * 16 + 21600) / 8; + CODE::Xorshift32 scrambler; + for (int i = 0; i < data_len; ++i) + output_data[i] ^= scrambler(); for (int i = 0; i < data_len; ++i) output_file.put(output_data[i]); delete []output_data; diff --git a/encode.cc b/encode.cc index 30fc31a..f4efcfb 100644 --- a/encode.cc +++ b/encode.cc @@ -7,6 +7,7 @@ Copyright 2021 Ahmet Inan #include #include #include +#include "xorshift.hh" #include "complex.hh" #include "utils.hh" #include "bitman.hh" @@ -35,8 +36,6 @@ struct Encoder static const int mls1_len = 255; static const int mls1_poly = 0b100101011; static const int mls2_poly = 0b100101010001; - static const int mls3_poly = 0b10001000000001011; - static const int mls4_poly = 0b10111010010000001; DSP::WritePCM *pcm; DSP::FastFourierTransform bwd; DSP::FastFourierTransform<4*symbol_len, cmplx, -1> fwd4; @@ -239,13 +238,10 @@ struct Encoder code[i] = nrz(CODE::get_le_bit(inp, i)); ldpcenc(code, code + bch_bits); interleave(); - CODE::MLS seq3(mls3_poly), seq4(mls4_poly); for (int j = 0; j < code_rows; ++j) { - for (int i = 0; i < code_cols; ++i) { - cmplx con = mod_map(bint+mod_bits*(code_cols*j+i)); - con = cmplx(con.real() * nrz(seq3()), con.imag() * nrz(seq4())); - fdom[bin(i+code_off)] *= con; - } + for (int i = 0; i < code_cols; ++i) + fdom[bin(i+code_off)] *= + mod_map(bint+mod_bits*(code_cols*j+i)); symbol(); } schmidl_cox(); @@ -345,6 +341,9 @@ int main(int argc, char **argv) uint8_t *input_data = new uint8_t[code_len]; for (int i = 0; i < data_len; ++i) input_data[i] = input_file.get(); + CODE::Xorshift32 scrambler; + for (int i = 0; i < data_len; ++i) + input_data[i] ^= scrambler(); DSP::WriteWAV output_file(output_name, output_rate, output_bits, output_chan); output_file.silence(output_rate);