|
|
1.1 ! root 1: /* lfsr.h - C header include file for lfsr.c ! 2: ** Linear Feedback Shift Register (LFSR) routines ! 3: ** (c) 1988 Philip Zimmermann. All rights reserved. ! 4: */ ! 5: ! 6: ! 7: /* Elaborate protection mechanisms to assure no redefinitions of types...*/ ! 8: #ifndef BYTESTUFF ! 9: #define BYTESTUFF ! 10: typedef unsigned char byte; /* values are 0-255 */ ! 11: typedef byte *byteptr; /* pointer to byte */ ! 12: typedef char *string; /* pointer to ASCII character string */ ! 13: #endif /* if BYTESTUFF not already defined */ ! 14: ! 15: ! 16: /* ! 17: ** steplfsr256 - Step big linear feedback shift register (LFSR) ! 18: ** 256 cycles. Use primitive polynomial: X^255 + X^82 + X^0 ! 19: ** Actually runs 8 LFSR's in parallel, outputting a whole byte ! 20: ** with each step. ! 21: */ ! 22: void steplfsr256(register byteptr lfsr); ! 23: ! 24: /* ! 25: ** getlfsr - get 1 byte from lfsr buffer. Must be macro, not function. ! 26: ** Calls steplfsr256() if necessary to replenish lfsr buffer. ! 27: */ ! 28: #define getlfsr(lfsr,rtail) (rtail ? lfsr[--rtail] : \ ! 29: (steplfsr256(lfsr),lfsr[--rtail])) ! 30: ! 31: ! 32: /* ! 33: ** initlfsr - initialize linear feedback shift register ! 34: */ ! 35: void initlfsr(byteptr seed, short size, byteptr lfsr, byte *rtail); ! 36: ! 37: /* ! 38: ** stomplfsr - inverts about half the bits in an LFSR. ! 39: ** ! 40: ** If the LFSR has a "rail" of almost all 0's or almost all 1's in ! 41: ** the same bit position, it will perform poorly as a random number ! 42: ** generator. This function will probably fix this condition. ! 43: */ ! 44: void stomplfsr(byteptr lfsr); ! 45: ! 46:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.