Ejemplo n.º 1
0
def initialize():
    config.init_random()
    config.generate_prime()
    config.generate_h_pwd()
    poly.generate_poly()
    if __debug__:
        pwd = reader.init("input.txt")
    else:
        pwd = reader.init(raw_input("enter the input file: "))
    table.generate(pwd, None)
    history.init()
Ejemplo n.º 2
0
        x = crypt.p(mpz(i << 1), config.r)
        y = gmpy2.sub(table[i - 1][0], crypt.g(mpz(i << 1), config.r ^ pwd))
        coordinates.append((x, y))
    return coordinates


# extract the coordinate at specified index
def extract_at(pwd, features, index):
    index += 1
    pwd = mpz(crypt.get_bit_str_from_byte(pwd), base=2)
    if features[index - 1] >= config.ti:  # pick the other column of the table
        x = crypt.p(mpz(index << 1), config.r)
        y = gmpy2.sub(table[index - 1][0], crypt.g(mpz(index << 1), config.r ^ pwd))
        return x, y
    else:
        x = crypt.p(mpz((index << 1) + 1), config.r)
        y = gmpy2.sub(table[index - 1][1], crypt.g(mpz((index << 1) + 1), config.r ^ pwd))
        return x, y

if __name__ == "__main__":
    # demonstrate the instruction table set up is correct
    config.init_random()
    config.generate_prime()
    config.generate_r()
    config.generate_h_pwd()
    poly.generate_poly()
    mock_pwd = "CorrectPassword"
    generate(mock_pwd, None)
    coordinates = extract(mock_pwd, [0])
    assert poly.get_h_pwd(coordinates) == config.h_pwd, "table initialization error!"
Ejemplo n.º 3
0
def update(pwd, feature):
    config.generate_h_pwd()  # generate the new h_pwd
    stat = history.add_feature(feature)  # add the new feature to history file and save it
    poly.generate_poly()  # generate the new polynomial
    table.generate(pwd, stat)  # generate the new table