A
A
art16362032018-04-27 05:42:11
Python
art1636203, 2018-04-27 05:42:11

How to "search" for a specific combination of bytes in PRNG?

There is a pseudo-random number generator - it displays (one byte at a time) a certain combination according to its algorithm:

bytes = ("%02x" % (algo))
sys.stdout.write(bytes)

Question: how to "search" for a specific combination of bytes?
For example, the output of the generator is a1b2c3d4e5f6, and you need to stop the program execution if exactly the given bytes d4e5 appear during the generation process ('d4', and immediately after it 'e5').
One byte at a time is clear:
if bytes == 'd4':
    exit(0)

But if the first value is correct, then what about checking the second (third, fourth, etc.) immediately after it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2018-04-27
@art1636203

# для длинного хвоста
tail = (None, None)
for r in 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6: # да, вот такой хреновый гпсч
    print("%02x" % r)
    tail = tail[1:] + (r,)
    if tail == (0xd4, 0xe5):
        break

# для короткого хвоста
t = None
for r in 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6:
    print("%02x" % r)
    if t == 0xd4 and r == 0xe5:
        break
    t = r

ps word bytes is already taken - read about it at your leisure .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question