def getResults(weightMatrix): print "Client: Loading secret key..." secretKey = getSecretKey() print "Client: Getting new secret key..." T, S = evaluate([ 'random-matrix', len(weightMatrix), 1, 'duplicate-matrix', 'get-secret-key' ]) print "Client: Getting key switch matrix..." keySwitch, = evaluate( [weightMatrix, secretKey, T, 'linear-transform-key-switch']) print "Client: Getting encrypted results from server..." encryptedResults = getLinearTransformations(keySwitch) print "Client: Decrypting results..." results = evaluate([S] + flatzip(inf('duplicate-matrix'), encryptedResults, inf('decrypt')))[:-1] print "Client: Done." print print return results
def run(self): print("processing search request") self.datareceive = recv_msg(self.c) self.publickey = pickle.loads(self.datareceive) self.results, = evaluate([filefeatures, self.publickey, 'encrypt_m']) self.datasend = pickle.dumps(self.results) send_msg(self.c, self.datasend) print("compelete") self.c.close()
def getResults(weightMatrix): print "Client: Loading secret key..." secretKey = getSecretKey(); print "Client: Getting new secret key..." T, S = evaluate(['random-matrix', len(weightMatrix), 1, 'duplicate-matrix', 'get-secret-key']) print "Client: Getting key switch matrix..." keySwitch, = evaluate([weightMatrix, secretKey, T, 'linear-transform-key-switch']) print "Client: Getting encrypted results from server..." encryptedResults = getLinearTransformations(keySwitch) print "Client: Decrypting results..." results = evaluate([S] + flatzip(inf('duplicate-matrix'), encryptedResults, inf('decrypt')))[:-1] print "Client: Done." print print return results
c for c in text.lower() if c not in bannedcharacters).split() if w in features).strip() def getfeature(text): feature = [0] * len(features) wordlist = simplify(text).split() for w in wordlist: feature[features[w]] += 1 return tuple(feature, ) for i in range(len(filenames)): doc = open(filenames[i], 'rb').read().decode('utf-8', 'ignore') if doc != "": featuremat.append(getfeature(doc)) print("features extracted") secretkey, publickey, ciphertext = evaluate([featuremat, "encrypt"]) with open('secretkey', 'wb') as f: pickle.dump(secretkey, f, pickle.HIGHEST_PROTOCOL) f.close() with open('publickey', 'wb') as f: pickle.dump(publickey, f, pickle.HIGHEST_PROTOCOL) f.close() with open('filefeatures', 'wb') as f: pickle.dump(ciphertext, f, pickle.HIGHEST_PROTOCOL) f.close()
def get_linear_transformation(features, keySwitchMatrix): from hevector import evaluate return evaluate([keySwitchMatrix] + flatzip(inf('duplicate-matrix'), features, inf('linear-transform')))[:-1]
def get_linear_transformation(features, keySwitchMatrix): from hevector import evaluate return evaluate([keySwitchMatrix] + flatzip(inf( 'duplicate-matrix'), features, inf('linear-transform')))[:-1]