コード例 #1
0
ファイル: main.py プロジェクト: crazytan/seclogin
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()
コード例 #2
0
ファイル: polynomial.py プロジェクト: crazytan/seclogin
    x = map(lambda x: x[0], coordinates)  # extract the x and y coordinates
    y = map(lambda x: x[1], coordinates)
    h_pwd_ = mpz()
    for i in xrange(config.max_features):
        h_pwd_ = gmpy2.add(h_pwd_, gmpy2.t_mod(gmpy2.mul(y[i], get_lambda_i(x, i)), config.q))
    h_pwd_ = gmpy2.t_mod(h_pwd_, config.q)
    return h_pwd_


# calculate the value of the polynomial at a point x
def calculate(x):
    ans = mpz()
    for c_i in c[::-1]:
        ans = gmpy2.t_mod(gmpy2.add(gmpy2.mul(ans, x), c_i), config.q)
    return ans

if __name__ == "__main__":
    # test for calculate
    config.init_random()
    config.generate_prime()
    c = [mpz(20), mpz(1), mpz(2)]
    print calculate(mpz(2))

    # test for generate_poly() and get_h_pwd
    config.generate_h_pwd()
    config.max_features = 127
    print "h_pwd: ", config.h_pwd
    generate_poly()
    coordinates = [(i, calculate(i)) for i in [mpz(j+1) for j in range(config.max_features)]]
    print "h_pwd_: ", get_h_pwd(coordinates)