Self-shrinking generator


Reading time: about 2 minutes

A self-shrinking generator is a PRNG that is a variant of the shrinking generator concept.

Algorithm

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. Generate two bits.
  2. If the first bit you generated is a 1, output the second bit.
  3. Otherwise, output nothing.
  4. Go to step 1.
In [2]:
def self_shrinking(generator):
    while True:
        first  = next(generator)
        second = next(generator)
    
        if first:
            yield second

Application to LFSRs

In [3]:
def 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 b
In [4]:
gen_output(lfsr(b"Hello world"))
gen_output(lfsr(b"Hello World"))
Out [4]:
'0111101100110011100111100110110011000010110101010100101010001110'
Out [4]:
'0010101111100110001001010100000110001110111001010100000011100011'
In [5]:
gen_output(self_shrinking(lfsr(b"Hello world")))
gen_output(self_shrinking(lfsr(b"Hello World")))
Out [5]:
'1011101001101000100110101000000001000111101010101111100010110000'
Out [5]:
'0011000010101011100001000100001000110011111011100001100001011110'

References and useful links

The following pages link here

Citation

If you find this work useful, please cite it as:
@article{yaltirakliwikiselfshrinkinggenerator,
  title   = "Self-shrinking generator",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2024",
  url     = "https://www.gkbrk.com/wiki/self-shrinking-generator/"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Self-shrinking generator", December, 2024. [Online]. Available: https://www.gkbrk.com/wiki/self-shrinking-generator/. [Accessed Dec. 17, 2024].
APA Style
Yaltirakli, G. (2024, December 17). Self-shrinking generator. https://www.gkbrk.com/wiki/self-shrinking-generator/
Bluebook Style
Gokberk Yaltirakli, Self-shrinking generator, GKBRK.COM (Dec. 17, 2024), https://www.gkbrk.com/wiki/self-shrinking-generator/

Comments

© 2024 Gokberk Yaltirakli