A self-shrinking generator is a PRNG that is a variant of the shrinking generator concept.
A self-shrinking generator wraps another pseudorandom bit generator and attempts to make it more difficult to guess the internal state from the output.
1, output the second bit.def self_shrinking(generator):
while True:
first = next(generator)
second = next(generator)
if first:
yield seconddef lfsr(key):
state = lfsr_key_deriv(key)
while True:
b = state[0]
b ^= state[2]
b ^= state[6]
b ^= state[7]
state.pop(0)
state.append(b)
yield bgen_output(lfsr(b"Hello world"))
gen_output(lfsr(b"Hello World"))'0111101100110011100111100110110011000010110101010100101010001110'
'0010101111100110001001010100000110001110111001010100000011100011'
gen_output(self_shrinking(lfsr(b"Hello world")))
gen_output(self_shrinking(lfsr(b"Hello World")))'1011101001101000100110101000000001000111101010101111100010110000'
'0011000010101011100001000100001000110011111011100001100001011110'