jeudi 9 avril 2020

How to make a truly improbable condition with limitations of Python's random?

So I am trying to find a way to get a massively improbable condition based on random generations. To better explain, here's an example:

from random import *
import ctypes

random1 = [randint(0, 2 ** 32 - 1) for j in range(10000000)]

while True:
    random2 = [randint(0, 2 ** 32 - 1) for i in range(10000000)]
    if set(random2) == set(random1):
        MessageBox = ctypes.windll.user32.MessageBoxW
        MessageBox(None, 'Match', 'Output', 0)
        break

Because of the limitations and functionality of mersene twister, and the uniformity of its distribution of numbers, it's quite likely we will generate 10 milion numbers in both lists, where when order doesn't matter and duplicates are removed, they will match quite often.

This is not that rare, but the following code is slightly better:

from random import *
import ctypes

while True:
    if random() == 0.0:
        MessageBox = ctypes.windll.user32.MessageBoxW
        MessageBox(None, 'Match', 'Output', 0)
        break

This is a lot less likely to happen, but with massive single core performance, quite common today, it's still easily likely to get a match in 1~ day. The probability being 1/2^56, and with the limitations of mersenne twister in mind, it's not that unlikely to happen.

Is there a good way to write a condition utilizing randomness in python that will truly be extremely unlikely to happen?.. That would say, take a year to crack, or more.

Alternatively I thought to turn to hash matching... creating a random SHA256 hash, then generating random big data, and hashing it through sha256 to try and match the hash. But I don't know a way to observe probability in that case.




Aucun commentaire:

Enregistrer un commentaire