|
#!/usr/bin/perl -w
# LFSR - Implement arbitrary-sized linear feedback
# shift registers
# Convert the seed from decimal to binary
$seed = dec2bin(shift);
@array = split('', $seed);
@xor_bits = @ARGV;
# Sure hope Perl always uses 32-bit ints!
splice(@array, 0, 31-$ARGV[0]);
# Let the user bang on <ENTER> until he's had his
# fill of random bits
while (1) {
getc();
$new_bit = 0 + $array[0]; # Yes, the "0 +" is necessary.
foreach (@xor_bits[1..$#xor_bits]) {
$new_bit ^= $array[$#array - $_];
}
print pop @array;
unshift (@array, $new_bit);
}
sub dec2bin { unpack("B*", pack("N", shift)) }
|
|