def DataUpload(trainData): trainDataNums,dim = trainData.shape #数据构造 trainDataReshape = np.zeros((trainDataNums, dim + 2), dtype=object) for i in range(trainDataNums): trainDataReshape[i][0] = 1 temp = trainData[i].dot(trainData[i].T) trainDataReshape[i][1] = temp for j in range(dim): trainDataReshape[i][j + 2] = trainData[i][j] dim = trainDataReshape.shape[1] #维度更新 #加密 # 初始化参数 T_cols = 1 Ps, Pm = mvhe.getinvertiblematrix(dim + T_cols) T = mvhe.getRandomMatrix(dim, T_cols, mvhe.tBound) S = mvhe.getSecretKey(T, Ps) #加密 encOftrainDataReshape = np.zeros((trainDataNums, dim + T.shape[1]), dtype=object) for i in range(trainDataNums): encOftrainDataReshape[i] = mvhe.encrypt(T, Pm, trainDataReshape[i]) return encOftrainDataReshape, S, T_cols
def data_enc(dataset): enc_dataset = np.zeros((row, col + K), dtype=object) for i in range(row): enc_dataset[i] = mvhe.encrypt(T, Mt, dataset[i]) return enc_dataset