def crack_rando_encr(ptext, ctext, isbytes=False):
    #finds the 16bit seed for the mt19937 encryption
    #where ptext was encrypted with rando_encr
    l0 = len(ptext)
    l1 = len(ctext)
    ind1 = int(l1 / 4) * 4 - 4
    ind0 = ind1 - l1
    if isbytes: bptext = ptext
    else: bptext = ptext.encode()
    b0 = int.from_bytes(
        (bptext[ind0], bptext[ind0 + 1], bptext[ind0 + 2], bptext[ind0 + 3]),
        'big')
    c0 = int.from_bytes(
        (ctext[ind1], ctext[ind1 + 1], ctext[ind1 + 2], ctext[ind1 + 3]),
        'big')
    r0 = b0 ^ c0
    #this is only gonna work for sure if ptext is long enough, like at least 7 or 8 chrs
    for i in range(0, 2**16):
        prn = 0
        mt.seed_mt(i)
        for j in range(0, int(ind1 / 4) + 1):
            prn = mt.extract_number()
        if prn == r0:
            return i
    return None
def waiting_seed_rng(lbd=40, ubd=1000, wait=True):
    wint = random.randint(lbd, ubd)
    if wait == True:  #actually wait
        time.sleep(wint)
        mt.seed_mt(int(time.time()))
        wint = random.randint(lbd, ubd)
        time.sleep(wint)
    else:  #simulate waiting
        mt.seed_mt(int(time.time() + wint))
    return mt.extract_number()
def crack_seed(rando, vals=10000):
    t0 = int(time.time())
    for i in range(0, vals):
        mt.seed_mt(t0 + i)
        if rando == mt.extract_number():
            return t0 + i
        mt.seed_mt(t0 - i - 1)
        if rando == mt.extract_number():
            return t0 - i - 1
    return None
Example #4
0
def make_mt19937_rand_list(idx, rng_s, rng_e):
    if rng_s > rng_e:
        rng_s, rng_e = rng_e, rng_s
    rand_list = {}
    for i in range(rng_s, rng_e):
        mt19937.seed_mt(i)
        for j in range(idx):
            mt19937.extract_number()
        rand_num = mt19937.extract_number()
        rand_list[rand_num] = i
    return rand_list
Example #5
0
def gen_pswd_ret_token(l=16):
    global orig_token, time_stamp
    token = ''
    cur_time = int(time.time())
    mt19937.seed_mt(cur_time)
    time_stamp = cur_time
    for i in range(l):
        token += chr(int(mt19937.random() * 256))
    token = base64.b64encode(token)
    orig_token = token
    return token
Example #6
0
def foo():
    t = my_rand.my_rand(10, 1)
    #t = my_rand.my_rand(1000, 10)
    time.sleep(t)

    seed = int(time.time())
    #print "seed:", seed
    mt19937.seed_mt(seed)

    t = my_rand.my_rand(10, 1)
    #t = my_rand.my_rand(1000, 10)
    time.sleep(t)

    return mt19937.extract_number(), seed
def check_pswd_tkn(seed, ctext, tkn):
    l1 = len(tkn)
    if (l1 % 4) != 0:
        return False
    l0 = len(ctext)
    if (l0 % 4) == 0:
        rlen = int(l0 / 4)
    else:
        rlen = int(l0 / 4) + 1
    mt.seed_mt(seed)
    for i in range(0, rlen):
        mt.extract_number()
    for i in range(0, int(l1 / 4)):
        if int.from_bytes(tkn[i * 4:i * 4 + 4], 'big') != mt.extract_number():
            return False
    return True
def gen_pswd_rst_tkn(seed, ctext, n=10):
    #generates an n*4 byte password reset token
    l0 = len(ctext)
    if (
            l0 % 4
    ) == 0:  #makes rlen = ceil(l0/4) but i didn't feel like using the math ceil function
        rlen = int(l0 / 4)
    else:
        rlen = int(l0 / 4) + 1
    mt.seed_mt(seed)
    for i in range(0, rlen):
        mt.extract_number()
    tkn = []
    for i in range(0, n):
        bts = (mt.extract_number()).to_bytes(4, 'big')
        tkn += [bts[0], bts[1], bts[2], bts[3]]
    return bytes(tkn)
def check_seed_consistency(seed):
    mt.seed_mt(seed)
    return mt.extract_number()
 def __init__(self, seed):
     self.index = 4
     self.fourbyte = 0
     import mt19937 as mt0
     mt0.seed_mt(seed)
     self.__extract4 = mt0.extract_number