コード例 #1
0
ファイル: main.py プロジェクト: crazytan/seclogin
def correction(pwd, feature):
    coordinates = table.extract(pwd, feature)
    for i in xrange(len(feature)):
        tmp = coordinates[i]  # save the original coordinate
        coordinates[i] = table.extract_at(pwd, feature, i)  # extract the other entry from table
        h_pwd_ = poly.get_h_pwd(coordinates)
        if history.decrypt(h_pwd_):
            return True
        coordinates[i] = tmp  # restore the original coordinate
    return False
コード例 #2
0
ファイル: main.py プロジェクト: crazytan/seclogin
def main():
    initialize()
    while reader.has_next():  # if there is still login attempts to process
        pwd, feature = reader.next_login()
        h_pwd_ = poly.get_h_pwd(table.extract(pwd, feature))  # use the coordinates extracted from table to get h_pwd
        if history.decrypt(h_pwd_):
            print 1
            update(pwd, feature)
        else:
            if correction(pwd, feature):
                print 1
                update(pwd, feature)
            else:
                print 0
コード例 #3
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!"