Skip to content

Instantly share code, notes, and snippets.

@basveeling
Created March 29, 2014 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basveeling/9856004 to your computer and use it in GitHub Desktop.
Save basveeling/9856004 to your computer and use it in GitHub Desktop.
class LFSR
@state = 0;
@taps = 0;
def initialize(state, taps)
@state = state
@taps = taps
end
def step
@state = (@state >> 1) ^ (-(@state & 1) & @taps);
return ((@state & 0x400) > 0) ? 1 : 0
end
end
lfsr = LFSR.new(0x100, 0x829)
(0...32).each do |i|
puts lfsr.step
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment