How to make a "search" for a particular combination of bytes in the PRNG?

0 like 0 dislike
There is a pseudo - random number generator outputs(one byte) a certain combination on the algorithm:
bytes = ("%02x" % (algo)) sys.stdout.write(bytes)

Question: how to implement "search" for a specific combination of bytes?
For example, the output of the generator - a1b2c3d4e5f6, and we need to stop the program if in the generation process will appear exactly the bytes specified d4e5 ('d4', followed immediately 'e5').

One byte is clear:
if bytes == 'd4': exit(0)

But if the first value is valid, then how about checking a second (third, fourth, etc.), immediately after it?
by | 3 views

1 Answer

0 like 0 dislike
# for the long tail tail = (None, None) for r in 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6: # Yes, this is such a shitty PRNG print("%02x" % r) tail = tail[1:] + (r) if tail == (0xd4, 0xe5): break # for short tail t = None for r in 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6: print("%02x" % r) if t == 0xd4 and r == 0xe5: break t = r

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

Related questions

0 like 0 dislike
2 answers
asked Jun 11, 2019 by avion123678
0 like 0 dislike
3 answers
0 like 0 dislike
3 answers
asked Mar 23, 2019 by Vladson
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
33,698 users