grid_real = generateGridByPlaneLocation(lat, lon)
        # 这里同样需要把网格分成COOR和TDOA进行加密

        print("开始加密实时生成网格的TDOA数据和H矩阵")
        grid_tdoa = grid_real[:, 4:]

        NUMBER = grid_tdoa.shape[0]
        DIMIENSION = grid_tdoa.shape[1]
        tdoa_int = np.zeros((NUMBER, DIMIENSION), dtype=object)
        for i in range(NUMBER):
            tdoa_int[i] = float2Int(grid_tdoa[i])
            # 初始化相关加密参数 注意这里的加密方式不是原生的VHE的加密,而是为了求欧式距离,特殊定义了一些加密方式
        T = vhe.getRandomMatrix(DIMIENSION, 1, vhe.tBound)
        S = vhe.getSecretKey(T)
        I = np.eye(DIMIENSION, dtype=object)
        M_TDOA = vhe.KeySwitchMatrix(I, T)

        # M可以用来进行加密了
        # 先定义一个numpy数组 来存储加密数据
        enc_tdoa = np.zeros((NUMBER, DIMIENSION + 1), dtype=object)
        # print("开始对%dm网格的%d条tdoa数据进行加密" % (SQURE_SIZE, NUMBER))
        t0 = time.time()
        for i in range(NUMBER):
            enc_tdoa[i] = vhe.encrypt_distance(M_TDOA, tdoa_int[i])
        M_float = np.array(M_TDOA, dtype=float)
        M_I = np.linalg.pinv(M_float)
        I_star = vhe.getBitMatrix(I)
        A = I_star.dot(M_I)
        H = A.T.dot(A)
        H_int = np.zeros((H.shape[0], H.shape[1]), dtype=object)
Example #2
0
    # print(DIMIENSION)

    print("将原始的coor数据转换为int类型,放大系数为:%d" % (S2NS))
    coor_int = np.zeros((NUMBER, DIMIENSION), dtype=object)
    for i in range(NUMBER):
        coor_int[i] = float2Int(coor[i])
    print("检查数据类型是否成功转换")
    if type(coor_int[0][0]) == int:
        print("成功把浮点型的tdoa转换为python原生的int类型")

    print("初始化加密参数")
    # 初始化相关加密参数 注意这里的加密方式不是原生的VHE的加密,而是为了求欧式距离,特殊定义了一些加密方式
    T = vhe.getRandomMatrix(DIMIENSION, 1, vhe.tBound)
    S = vhe.getSecretKey(T)
    I = np.eye(DIMIENSION, dtype=object)
    M = vhe.KeySwitchMatrix(I, T)

    # M可以用来进行加密了
    # 先定义一个numpy数组 来存储加密数据
    enc_coor = np.zeros((NUMBER, DIMIENSION + 1), dtype=object)
    print("开始对%dm网格的%d条coor数据进行加密" % (SQURE_SIZE, NUMBER))
    t0 = time.time()
    for i in range(NUMBER):
        enc_coor[i] = vhe.encrypt_distance(M, coor_int[i])

        if (i + 1) % 10000 == 0:
            print("已完成%d条数据的加密,当前进度为%.2f%%" % ((i + 1),
                                               ((i + 1) / NUMBER) * 100))
    #
    t1 = time.time()
    print("完成加密,耗时%.2f秒" % (t1 - t0))