mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
used bitman to help clean up the mess
This commit is contained in:
parent
abe4edc419
commit
537aff62a2
4 changed files with 28 additions and 34 deletions
|
|
@ -7,6 +7,7 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
|||
#include <cassert>
|
||||
#include <random>
|
||||
#include <iostream>
|
||||
#include "bitman.hh"
|
||||
#include "galois_field.hh"
|
||||
#include "bose_chaudhuri_hocquenghem_decoder.hh"
|
||||
|
||||
|
|
@ -27,10 +28,8 @@ int main()
|
|||
code[i] = target[i];
|
||||
std::uniform_int_distribution<int> distribution(0, BCH::N-1);
|
||||
auto noise = std::bind(distribution, generator);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int n = noise();
|
||||
code[n / 8] ^= 128 >> (n % 8);
|
||||
}
|
||||
for (int i = 0; i < 3; ++i)
|
||||
CODE::xor_be_bit(code, noise(), 1);
|
||||
decode(code);
|
||||
for (int i = 0; i < L; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
|
|
@ -46,19 +45,17 @@ int main()
|
|||
for (int i = 0; i < L; ++i)
|
||||
target[i] = 0;
|
||||
for (int i = 0, s = 0; i < BCH::K; ++i, s=(s*(s*s*51767+71287)+35149)&0xffffff)
|
||||
target[i/8] |= ((s^=s>>7)&1) << (7-i%8);
|
||||
CODE::set_be_bit(target, i, (s^=s>>7)&1);
|
||||
bool parity[BCH::NP] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 };
|
||||
for (int i = 0; i < BCH::NP; ++i)
|
||||
target[(BCH::K+i)/8] |= parity[i] << (7-(BCH::K+i)%8);
|
||||
CODE::set_be_bit(target, BCH::K+i, parity[i]);
|
||||
uint8_t *code = new uint8_t[L];
|
||||
for (int i = 0; i < L; ++i)
|
||||
code[i] = target[i];
|
||||
std::uniform_int_distribution<int> distribution(0, BCH::N-1);
|
||||
auto noise = std::bind(distribution, generator);
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
int n = noise();
|
||||
code[n / 8] ^= 128 >> (n % 8);
|
||||
}
|
||||
for (int i = 0; i < 12; ++i)
|
||||
CODE::xor_be_bit(code, noise(), 1);
|
||||
(*decode)(code);
|
||||
for (int i = 0; i < L; ++i)
|
||||
assert(code[i] == target[i]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue