Exemplo n.º 1
0
def generate_keystream(text, seed):
    keystream = ''
    rng = mersenne_rng(seed = seed)
    while len(keystream)<len(text):
        rn = rng.get_random_number()
        next_char_bin = bin(rn)[-8:]
        next_char = chr(int(next_char_bin,2))
        keystream+=next_char
    return keystream
Exemplo n.º 2
0
def get_first_rn():
    seed = random.randint(1000,500000)
    rng = mersenne_twister.mersenne_rng(seed = seed)
    return seed, rng.get_random_number()
Exemplo n.º 3
0

def crack_seed(first_randint):
    s0 = get_state_0(first_randint)
    return s0

def test_first_shift():
    for i in range(100):
        x = random.randint(100,1000000)
        y = x^(x>>11)
        assert back_out_right_shift(y,11)==x
    print 'test complete'

def test_second_shift():
    for i in range(100):
        x = random.randint(100,1000000)
        y = x^((x<<7)&0x9D2C5680)
        assert back_out_left_shift_and(y,7,0x9D2C5680)==x
    print 'test complete'



if __name__ == "__main__":
    seed, rn = get_first_rn()
    for i in range(1000,500000):
        m = mersenne_twister.mersenne_rng(seed = i)
        if rn == m.get_random_number():
            print "Seed guess: "+str(i)
            print "Actual seed: "+str(seed)
            break
Exemplo n.º 4
0
def get_first_rn():
    seed = random.randint(1000, 500000)
    rng = mersenne_twister.mersenne_rng(seed=seed)
    return seed, rng.get_random_number()
Exemplo n.º 5
0
def crack_seed(first_randint):
    s0 = get_state_0(first_randint)
    return s0


def test_first_shift():
    for i in range(100):
        x = random.randint(100, 1000000)
        y = x ^ (x >> 11)
        assert back_out_right_shift(y, 11) == x
    print 'test complete'


def test_second_shift():
    for i in range(100):
        x = random.randint(100, 1000000)
        y = x ^ ((x << 7) & 0x9D2C5680)
        assert back_out_left_shift_and(y, 7, 0x9D2C5680) == x
    print 'test complete'


if __name__ == "__main__":
    seed, rn = get_first_rn()
    for i in range(1000, 500000):
        m = mersenne_twister.mersenne_rng(seed=i)
        if rn == m.get_random_number():
            print "Seed guess: " + str(i)
            print "Actual seed: " + str(seed)
            break
Exemplo n.º 6
0
def get_rng():
    seed = 438276439281463287
    return mersenne_rng(seed = int(seed))
Exemplo n.º 7
0
def create_new_rng(original_state):
    new_rng = mersenne_rng()
    new_rng.state = original_state
    new_rng.index = 624
    return new_rng