def mt19937_streamcipher(text, seed):
    out = bytes()
    m = mt32(seed)

    for offset in range(len(text)):
        keystream = (m.extract_number() % 256)
        out += bytes([text[offset] ^ keystream])

    return out
Exemple #2
0
from level21_mt19937 import mt32
from random import randint
import time

# Generates 32 random numbers with mt32 algorithms, with a random seed.
# The filename contains the seed value

time.sleep(randint(0, 10))
random_seed = int(time.time())

mt = mt32(random_seed)

with open(str("mt32/") + str(random_seed) + '.mt32', 'w') as f:
    for i in range(32):
        time.sleep(randint(0, 3))
        f.write(str(mt.extract_number()) + "\n")

f.close()
def get_values_by_seed(seed):
    mt = mt32(seed)
    return [mt.extract_number() for i in range(32)]
def compare_by_seed(seed, expected):
    mt = mt32(seed)
    for i in range(32):
        if (mt.extract_number() != expected_values[i]):
            return False
    return True
def generate_token(seed):
    m = mt32(seed)
    return hexlify(bytes([m.extract_number() % 256 for i in range(16)]))