23
/* typedef struct { */
24
/* uint32_t register[8]; */
28
compute_period(uint32_t feedback_polynomial) {
33
mask.value = feedback_polynomial;
36
printf("polynomial: %s\t", v32_bit_string(mask));
38
for (i=0; i < 256; i++) {
39
/* printf("%s\n", v32_bit_string(lfsr)); */
40
if (parity(mask.value & lfsr.value))
41
lfsr.value = ((lfsr.value << 1) | 1) & 0xff;
43
lfsr.value = (lfsr.value << 1) & 0xff;
45
/* now halt if we're back at the initial state */
46
if (lfsr.value == 1) {
47
printf("period: %d\n", i);
56
uint32_t polynomials[39] = {
98
char binary_string[32];
101
u32_bit_string(uint32_t x, unsigned int length) {
107
for (; mask > 0; mask >>= 1)
109
binary_string[index++] = '0';
111
binary_string[index++] = '1';
113
binary_string[index++] = 0; /* NULL terminate string */
114
return binary_string;
117
extern int octet_weight[256];
120
weight(uint32_t poly) {
123
/* note: endian-ness makes no difference */
124
wt += octet_weight[poly & 0xff];
125
wt += octet_weight[(poly >> 8) & 0xff];
126
wt += octet_weight[(poly >> 16) & 0xff];
127
wt += octet_weight[(poly >> 24)];
132
#define MAX_PERIOD 65535
134
#define debug_print 0
137
period(uint32_t poly) {
145
printf("%d:\t%s\n", 0, u32_bit_string(x,8));
147
for (i=1; i < MAX_PERIOD; i++) {
154
/* print for a sanity check */
155
printf("%d:\t%s\n", i, u32_bit_string(x,8));
158
/* check for return to original value */
166
* weight distribution computes the weight distribution of the
167
* code generated by the polynomial poly
171
#define MAX_WEIGHT (1 << MAX_LEN)
176
weight_distribution2(uint32_t poly, int *A) {
181
for (i=0; i < MAX_WEIGHT+1; i++)
184
/* loop over all input sequences */
190
printf("%d:\t%s\n", 0, u32_bit_string(x,8));
192
for (i=1; i < MAX_PERIOD; i++) {
199
/* print for a sanity check */
200
printf("%d:\t%s\n", i, u32_bit_string(x,8));
203
/* increment weight */
206
/* check for return to original value */
217
weight_distribution(uint32_t poly, int *A) {
222
for (i=0; i < MAX_WEIGHT+1; i++)
228
printf("%d:\t%s\n", 0, u32_bit_string(x,8));
230
for (i=1; i < MAX_PERIOD; i++) {
237
/* print for a sanity check */
238
printf("%d:\t%s\n", i, u32_bit_string(x,8));
241
/* compute weight, increment proper element */
244
/* check for return to original value */
263
/* originally 0xaf */
266
printf("polynomial: %s\tperiod: %d\n",
267
u32_bit_string(p.value,8), period(p.value));
269
/* compute weight distribution */
270
weight_distribution(p.value, A);
272
/* print weight distribution */
273
for (i=0; i <= 8; i++) {
274
printf("A[%d]: %d\n", i, A[i]);
278
for (i=0; i < 39; i++) {
279
printf("polynomial: %s\tperiod: %d\n",
280
u32_bit_string(polynomials[i],8), period(polynomials[i]));
282
/* compute weight distribution */
283
weight_distribution(p.value, A);
285
/* print weight distribution */
286
for (j=0; j <= 8; j++) {
287
printf("A[%d]: %d\n", j, A[j]);
295
for (y=0; y < (1 << bits); y++) {
296
printf("polynomial: %s\tweight: %d\tperiod: %d\n",
297
u32_bit_string(y,bits), weight(y), period(y));
299
/* compute weight distribution */
300
weight_distribution(y, A);
302
/* print weight distribution */
303
for (j=0; j <= 8; j++) {
304
printf("A[%d]: %d\n", j, A[j]);