Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

(tye)Re: LFSR golf

by tye (Sage)
on May 08, 2001 at 09:09 UTC ( [id://78768]=note: print w/replies, xml ) Need Help??


in reply to LFSR golf

Here is a bit more on what an LFSR is.

A LFSR is a register of N bits. Two or more positions are designated as "taps" and the bit values from those positions are XOR'd together to produce a new bit. This bit is placed to the left of the register and all bits are then shifted to the right with the previous right-most bit being returned as the output.

       4   3   2   1   0   <- tap location numbers
     +---+---+---+---+---+
  ,->| 0 | 1 | 0 | 1 | 0 | -> Output
  |  +---+---+---+---+---+
  |        |           |
  |        |           |
  |        `->--XOR--<-'
  |              |
  `-------<------'

You repeat this process forever, producing a somewhat random stream of bits as a result.

A good LFSR will repeat the pattern of bits produced only after (2**N)-1 interations. For each size of LFSR, there are positions for the taps that result in such a "good" LFSR. Unless, of course, you seed it with a value of 0, which will always stay 0 since the XOR of any number of 0 bits is another 0 bit. Note, that is why the period can't be larger than (2**N)-1 since there are 2**N possible states and one of them (the value 0) can't be part of the loop.

You can go to http://www.google.com/ and search for LFSR to get more information on these. The person who pointed these out to me also pointed me to the book Applied Cryptography.

From my quick introduction to these, I'm starting to think that most of the material on them is a bit sloppy. (:

It seems to me that if you have an odd number of taps, then either a seed of 0 or of all 1 bits would never change (the XOR of an odd number of 1 bits is another 1 bit). But most of the "good" arrangements of taps have an odd number of taps [ which means that the maximum period for an odd number of taps would be (2**N)-2 ].

So I think we should really be using XNOR instead of XOR. Though I'm reluctant to jump to many conclusions since I've just barely learned of them. :)

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: LFSR golf
by jepri (Parson) on May 08, 2001 at 11:29 UTC

    You repeat this process forever, producing a somewhat random stream of bits as a result.

    It might be better if you said a 'disordered' stream, or 'complicated', 'lacking pattern'

    The output is not random because it will be the same for the same initial setting of the register (like the 'random' number generator on most computers)

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

      Like you mentioned, so-called "pseudorandom" number sequences are also identical for the same initial seed. I felt that "somewhat random" was less strong of a statement than "pseudorandom", but I can see where others would disagree. So I probably should have just stuck with "pseudorandom".

      For what it's worth, I find "disordered" and "lacking pattern" worse (the bits have a definite pattern and order). ;)

      This reminds me that I forgot to mention that the bit stream from a single LFSR has been studied to the point that a small subseries of bits is enough to predict the entire series. However, two carefully chosen LFSRs where each bit from one is used to determine whether the next bit from the other will be output or thrown away has been analyzed and found to be cryptographically strong.

              - tye (but my friends call me "Tye")
Re: (tye)Re: LFSR golf
by Adam (Vicar) on May 08, 2001 at 15:22 UTC
    Perhaps a more interesting challange would be an implementation of the Berlkamp-Massey algorithm. This algorithm capitalizes on knowing some series of bits produced by the LFSR (at least 2N bits, where N is the number of bits in the register) and determining what the taps are.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://78768]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-29 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found