def __init__(self, output, jsonFile): self.bidsDir = os.path.abspath(output) self.masterDicomsDir = os.path.dirname(os.path.abspath(jsonFile)) self.json = utils.loadJsonFile(jsonFile) self.participant = participant.Participant(self.json["participant"]) self.session = session.Session(self.json) self.session.setDir(self.bidsDir, self.participant.getName()) self.acquisitions = self.__setAcquisitions() self.converter = converter.Converter()
def testMatrix(mlist): encrypted1 = [0 for i in range(len(mlist))] encrypted2 = [0 for i in range(len(mlist))] for i in range(len(mlist)): par = participant.Participant(g, N, h) encrypted1[i], encrypted2[i] = par.encryption(mlist[i]) matrix1, matrix2 = miner.buildMatrix(encrypted1, encrypted2) matrix1, matrix2 = sqs.decryptMatrixFirst(matrix1, matrix2) # matrix = qp.decryptMatrixSecond(matrix1, matrix2) # order = qp.orderNumbers(matrix) ans = qp.getLastK(2, matrix1, matrix2) print(ans)
def comparison(mi, mj): par1 = participant.Participant(g, N, h) cmi1, cmi2 = par1.encryption(mi) par2 = participant.Participant(g, N, h) cmj1, cmj2 = par1.encryption(mj) f = random.randint(1, int((N // 2)**0.5)) temp1 = util.calculate_expo_mod(cmj1, N - 1, N2) temp1 = (temp1 * cmi1) % N2 temp1 = util.calculate_expo_mod(temp1, f, N2) temp2 = util.calculate_expo_mod(cmj2, N - 1, N2) temp2 = (temp2 * cmi2) % N2 temp2 = util.calculate_expo_mod(temp2, f, N2) print("cm1: ") print(temp1) print("cm2: ") print(temp2) cm1prime, cm2prime = sqs.decryptNumberFirst(temp1, temp2) print("cm1prime: ") print(cm1prime) print("cm2prime: ") print(cm2prime) decryptedM = qp.decryptNumberSecond(cm1prime, cm2prime) print("decrypted message: ") print(decryptedM)
def testOne(m): par = participant.Participant(g, N, h) cm1, cm2 = par.encryption(m) print("cm1: ") print(cm1) print("cm2: ") print(cm2) cm1prime, cm2prime = sqs.decryptNumberFirst(cm1, cm2) print("cm1prime: ") print(cm1prime) print("cm2prime: ") print(cm2prime) decryptedM = qp.decryptNumberSecond(cm1prime, cm2prime) print("decrypted message: ") print(decryptedM)
def testMultipleChoice(list, x): par = participant.Participant(g, N, h) cm1, cm2 = par.encryptMultipleChoice(list, x) print("cm1: ") print(cm1) print("cm2: ") print(cm2) cm1prime, cm2prime = sqs.decryptNumberFirst(cm1, cm2) print("cm1prime: ") print(cm1prime) print("cm2prime: ") print(cm2prime) decryptedM = qp.getMultipleChoiceCounting(cm1prime, cm2prime, x, len(list)) print("decrypted message: ") print(decryptedM)
def main(): global participants n = node.PoolNode(-1, None) epoch_0 = n.state.get_epoch(0) pool_pk = {} for p_idx in range(1, config.NUMBER_OF_POOLS + 1): ids = epoch_0.pool_participants_by_id(p_idx) logging.debug("Pool %d participants: %s (via DKG)", p_idx, ids) dkg = crypto.DKG(config.POOL_THRESHOLD - 1, ids) # following Shamir's secret sharing, degree is threshold - 1 dkg.run() sks = dkg.calculate_participants_sks() logging.debug(" Group sk: %s", dkg.group_sk()) logging.debug(" Group pk: %s", crypto.readable_pk(dkg.group_pk()).hex()) for i in sks: p = participant.Participant(i, sks[i]) p.limit_computation_to_ids = [4] participants.append(p) pool_pk[p_idx] = crypto.readable_pk(dkg.group_pk()) # connect all participants together and update them with groups logging.debug("connecting participants to each-other") for i in range(len(participants)): for p_idx in pool_pk: participants[i].node.state.save_pool_info(p_idx, pool_pk[p_idx]) # connect nodes to each other for j in range(i+1, len(participants)): participants[i].node.connect(participants[j].node) participants[j].node.connect(participants[i].node) # subscribe all nodes to topics for t in [config.MSG_SHARE_DISTRO,config.MSG_EPOCH_SIG]: for p in participants: p.node.subscribe_to_topic(p.id,t) # start epoch execution [threading.Thread(target=p.node.execute_epoch, daemon=True).start() for p in participants] # start epoch logging run_continously(participants[1].node)
def testMultiplication(): cm1 = 1 cm2 = 1 m = [7, 8, 9, 8, 6, 8] for i in range(6): par1 = participant.Participant(g, N, h) cmi1, cmi2 = par1.encryption(m[i]) cm1 = (cm1 * cmi1) % N2 cm2 = (cm2 * cmi2) % N2 print("cm1: ") print(cm1) print("cm2: ") print(cm2) cm1prime, cm2prime = sqs.decryptNumberFirst(cm1, cm2) print("cm1prime: ") print(cm1prime) print("cm2prime: ") print(cm2prime) # decryptedM = qp.decryptNumberSecond(cm1prime, cm2prime) # print("decrypted message: ") # print(decryptedM) avg = qp.getAverage(cm1prime, cm2prime, 6) print("average: ") print(avg)
#!/usr/bin/env python import os import channel import coordinator import participant chan = channel.Channel() chan.channel.flushall() NP = 3 coord = coordinator.Coordinator() parts = [participant.Participant() for i in range(NP)] pid = os.fork() if pid == 0: coord.run() os._exit(0) for i in range(NP): pid = os.fork() if pid == 0: parts[i].run() os._exit(0)