2022-07-20 07:07:00 +00:00
|
|
|
// Copyright 2020 Mobilinkd LLC.
|
2022-06-07 01:22:18 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
|
2022-07-31 03:15:58 +00:00
|
|
|
#include "export.h"
|
2022-07-04 21:03:07 +00:00
|
|
|
namespace modemm17
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
|
|
|
|
2022-07-31 03:15:58 +00:00
|
|
|
struct MODEMM17_API M17Randomizer
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
2022-07-31 02:54:39 +00:00
|
|
|
std::array<int8_t, 368> dc_;
|
2022-06-07 01:22:18 +00:00
|
|
|
|
|
|
|
M17Randomizer()
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
2022-07-31 02:54:39 +00:00
|
|
|
for (auto b : DC)
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
|
|
|
for (size_t j = 0; j != 8; ++j)
|
|
|
|
{
|
|
|
|
dc_[i++] = (b >> (7 - j)) & 1 ? -1 : 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Randomize and derandomize are the same operation.
|
2022-07-31 02:54:39 +00:00
|
|
|
void operator()(std::array<int8_t, 368>& frame)
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
2022-07-31 02:54:39 +00:00
|
|
|
for (size_t i = 0; i != 368; ++i)
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
|
|
|
frame[i] *= dc_[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 02:54:39 +00:00
|
|
|
void randomize(std::array<int8_t, 368>& frame)
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
2022-07-31 02:54:39 +00:00
|
|
|
for (size_t i = 0; i != 368; ++i)
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
|
|
|
frame[i] ^= (dc_[i] == -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 02:54:39 +00:00
|
|
|
private:
|
|
|
|
static const std::array<uint8_t, 46> DC;
|
2022-06-07 01:22:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-07-04 21:03:07 +00:00
|
|
|
} // modemm17
|