Skip to content

Commit

Permalink
find primitive poly of smaller symbol sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-armstrong committed Oct 14, 2016
1 parent 5d05070 commit 9b4031f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tools/find_rs_primitive_poly.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "correct/reed-solomon.h"

size_t block_size = 255;
int power_max = 8;

// visit all of the elements from the poly
bool trypoly(field_operation_t poly, field_logarithm_t *log) {
memset(log, 0, 256);
memset(log, 0, block_size + 1);
field_operation_t element = 1;
log[0] = (field_logarithm_t)0;
for (field_operation_t i = 1; i < 256; i++) {
for (field_operation_t i = 1; i < block_size + 1; i++) {
element = element * 2;
element = (element > 255) ? (element ^ poly) : element;
element = (element > block_size) ? (element ^ poly) : element;
if (log[element] != 0) {
return false;
}
Expand All @@ -17,28 +20,28 @@ bool trypoly(field_operation_t poly, field_logarithm_t *log) {
}

int main() {
field_logarithm_t *log = malloc(256 * sizeof(field_logarithm_t));
for (field_operation_t i = 0x100; i < 0x200; i++) {
field_logarithm_t *log = malloc((block_size + 1) * sizeof(field_logarithm_t));
for (field_operation_t i = (block_size + 1); i < (block_size + 1) << 1; i++) {
if (trypoly(i, log)) {
printf("0x%x valid: ", i);
field_operation_t poly = i;
int power = 8;
int power = power_max;
while(poly) {
if (poly & 0x100) {
if (poly & (block_size + 1)) {
if (power > 1) {
printf("x^%d", power);
} else if (power) {
printf("x");
} else {
printf("1");
}
if (poly & 0xff) {
if (poly & block_size) {
printf(" + ");
}
}
power--;
poly <<= 1;
poly &= 0x1ff;
poly &= (block_size << 1) + 1;
}
printf("\n");
}
Expand Down

0 comments on commit 9b4031f

Please sign in to comment.