in reply to Re^2: LFSRs & binary encode / decode functions
in thread LFSRs & binary encode / decode functions

Except for the initial value of the register, there are no inputs (as shown by the code below). What bit sequence are you talking about when you say "When used to encode a bit sequence"?

use strict; use warnings; sub make_lfsr { my ($size, $taps, $seed) = @_; my $mask = 2**$size - 1; my @taps = grep $_, map $_-1, sort { $b <=> $a } (@$taps); my $r = $seed; return sub { my $bit = 0; $bit ^= ($r >> $_) & 1 for @taps; $r = (($r << 1) & $mask) | $bit; }; } sub to_binary { my ($i, $size) = @_; return substr(unpack('B32', pack('N', $i)), -$size); } { my $size = 16; my @taps = (16, 14, 13, 11, 1); my $seed = 1; my $lfsr = make_lfsr($size, \@taps, $seed); for (;;) { my $r = $lfsr->(); print(to_binary($r, $size), "\n"); last if $r == $seed; } }

Update: Added code