/***** 65535 *****/ #include #include int main() { unsigned i, r, poly, count; FILE *file; file = fopen("p65535", "w"); if (file == NULL) return 1; printf("List of polynomials with period 65535\n"); fprintf(file, "List of polynomials with period 65535\n"); count = 0; poly = 0x8000U; do { i = 0; r = 1; do { if (r & 1) r = (r >> 1) ^ poly; else r >>= 1; i++; } while (r != 1); if (i == 65535U) { printf(" %04X", poly); fprintf(file, " %04X", poly); if (++count % 10 == 0) { printf("\n"); fprintf(file, "\n"); } } } while (poly++ != 0xFFFFU); printf("\n%u polynomials\n", count); fprintf(file, "\n%u polynomials\n", count); fclose(file); return EXIT_SUCCESS; } /***** 32767 *****/ #include #include int main() { unsigned i, r, poly, count; static unsigned a[4096]; FILE *file; file = fopen("p32767", "w"); if (file == NULL) return 1; printf("List of polynomials with period 32767\n"); fprintf(file, "List of polynomials with period 32767\n"); count = 0; poly = 0x8000U; do { for (i = 0; i < 4096; i++) a[i] = 0; i = 0; r = 1; do { if (r & 1) r = (r >> 1) ^ poly; else r >>= 1; i++; a[r >> 4] |= 1U << (r & 15); } while (r != 1); if (i != 32767U) continue; i = 0; r = 3; do { if (r & 1) r = (r >> 1) ^ poly; else r >>= 1; i++; if (a[r >> 4] & (1U << (r & 15))) break; } while (r != 3); if (i != 32767U) continue; printf(" %04X", poly); fprintf(file, " %04X", poly); if (++count % 10 == 0) { printf("\n"); fprintf(file, "\n"); } } while (poly++ != 0xFFFFU); printf("\n%u polynomials\n", count); fprintf(file, "\n%u polynomials\n", count); fclose(file); return EXIT_SUCCESS; }