Ejemplo n.º 1
0
def main():
    network = Network.get_instance()
    nodes = ['A', 'B', 'C', 'D', 'E']
    network.start(nodes)

    host_A = Host('A')
    host_A.add_connections(['B', 'C', 'D', 'E'])
    host_A.start()
    host_B = Host('B')
    host_B.add_c_connections(['C', 'D', 'E'])
    host_B.start()
    host_C = Host('C')
    host_C.add_c_connections(['B', 'D', 'E'])
    host_C.start()
    host_D = Host('D')
    host_D.add_c_connections(['B', 'C', 'E'])
    host_D.start()
    host_E = Host('E')
    host_E.add_c_connections(['B', 'C', 'D'])
    host_E.start()

    network.add_hosts([host_A, host_B, host_C, host_D, host_E])

    for i in range(10):
        # The ID of the generated secret EPR pair has to be agreed upon in advance
        epr_id = '123'
        host_A.run_protocol(distribute, ([host_B.host_id, host_C.host_id, host_D.host_id, host_E.host_id],))
        host_B.run_protocol(node, (host_A.host_id,))
        host_C.run_protocol(node, (host_A.host_id,))
        host_D.run_protocol(sender, (host_A.host_id, host_E.host_id, epr_id))
        host_E.run_protocol(receiver, (host_A.host_id, host_D.host_id, epr_id), blocking=True)
        time.sleep(0.5)
    network.stop(True)
Ejemplo n.º 2
0
def main():
    network = Network.get_instance()

    # backend = ProjectQBackend()
    backend = CQCBackend()

    nodes = ['A', 'B', 'C']
    network.start(nodes, backend)
    network.delay = 0.1

    host_A = Host('A', backend)
    host_A.add_connection('B')
    host_A.delay = 0
    host_A.start()

    host_B = Host('B', backend)
    host_B.add_connections(['A', 'C'])
    host_B.delay = 0
    host_B.start()

    host_C = Host('C', backend)
    host_C.add_connection('B')
    host_C.delay = 0
    host_C.start()

    network.add_host(host_A)
    network.add_host(host_B)
    network.add_host(host_C)

    t1 = host_A.run_protocol(protocol_1, (host_C.host_id, ))
    t2 = host_C.run_protocol(protocol_2, (host_A.host_id, ))

    t1.join()
    t2.join()
    network.stop(True)
Ejemplo n.º 3
0
    def test_add_connections(self):
        a = Host('A')

        a.add_connection('B')
        self.assertEqual(len(a.classical_connections), 1)
        self.assertEqual(len(a.quantum_connections), 1)

        a.add_c_connection('C')
        self.assertEqual(len(a.classical_connections), 2)
        self.assertEqual(len(a.quantum_connections), 1)

        a.add_q_connection('D')
        self.assertEqual(len(a.classical_connections), 2)
        self.assertEqual(len(a.quantum_connections), 2)

        a.add_connections(['E', 'F'])
        self.assertEqual(len(a.classical_connections), 4)
        self.assertEqual(len(a.quantum_connections), 4)

        a.add_c_connections(['G', 'H'])
        self.assertEqual(len(a.classical_connections), 6)
        self.assertEqual(len(a.quantum_connections), 4)

        a.add_q_connections(['I', 'J'])
        self.assertEqual(len(a.classical_connections), 6)
        self.assertEqual(len(a.quantum_connections), 6)
Ejemplo n.º 4
0
def main():
    network = Network.get_instance()
    network.start()

    host_alice = Host('Alice')
    host_bob = Host('Bob')
    host_eve = Host('Eve')

    host_alice.add_connection('Bob')
    host_bob.add_connections(['Alice', 'Eve'])
    host_eve.add_connection('Bob')

    host_alice.start()
    host_bob.start()
    host_eve.start()

    network.add_host(host_alice)
    network.add_host(host_bob)
    network.add_host(host_eve)

    t1 = host_alice.run_protocol(sender_protocol, ('Eve',))
    t2 = host_eve.run_protocol(receiver_protocol, ('Alice',))

    t1.join()
    t2.join()
    network.stop(True)
Ejemplo n.º 5
0
def main():
    network = Network.get_instance()
    network.start()

    host_alice = Host('Alice')
    host_bob = Host('Bob')
    host_eve = Host('Eve')

    host_alice.add_connection('Bob')
    host_bob.add_connections(['Alice', 'Eve'])
    host_eve.add_connection('Bob')

    host_alice.start()
    host_bob.start()
    host_eve.start()

    network.add_hosts([host_alice, host_bob, host_eve])

    q = Qubit(host_alice)
    print(q.id)
    q.X()

    host_alice.send_epr('Eve', await_ack=True)
    print('done')
    host_alice.send_teleport('Eve', q, await_ack=True)
    q_eve = host_eve.get_data_qubit(host_alice.host_id, q.id, wait=5)

    assert q_eve is not None
    print(q.id)
    print('Eve measures: %d' % q_eve.measure())
    network.stop(True)
Ejemplo n.º 6
0
def build_network_b92(eve_interception):

    network = Network.get_instance()

    nodes = ['Alice', 'Bob', 'Eve']
    network.start(nodes)

    host_alice = Host('Alice')
    host_bob = Host('Bob')
    host_eve = Host('Eve')

    host_alice.add_connection('Eve')
    host_eve.add_connections(['Alice', 'Bob'])
    host_bob.add_connection('Eve')
    # adding the connections - Alice wants to transfer an encrypted message to Bob
    # The network looks like this: Alice---Eve---Bob

    host_alice.delay = 0.3
    host_bob.delay = 0.3

    # starting
    host_alice.start()
    host_bob.start()
    host_eve.start()

    network.add_hosts([host_alice, host_bob, host_eve])

    if eve_interception == True:
        host_eve.q_relay_sniffing = True
        host_eve.q_relay_sniffing_fn = eve_sniffing_quantum

    hosts = [host_alice, host_bob, host_eve]
    print('Made a network!')
    return network, hosts
Ejemplo n.º 7
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve"]
    network.start(nodes)
    network.delay = 0.1

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.add_connections(['Alice', 'Eve'])
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connection('Bob')
    host_eve.start()

    network.add_hosts([host_alice, host_bob, host_eve])

    host_bob.q_relay_sniffing = True
    host_bob.q_relay_sniffing_fn = bob_sniffing_quantum

    host_bob.c_relay_sniffing = True
    host_bob.c_relay_sniffing_fn = bob_sniffing_classical

    t1 = host_alice.run_protocol(alice)
    t2 = host_eve.run_protocol(eve)

    t1.join()
    t2.join()

    network.stop(True)
    exit()
Ejemplo n.º 8
0
 def test_remove_connections(self):
     a = Host('A')
     a.add_connections(['B', 'C'])
     self.assertEqual(len(a.classical_connections), 2)
     self.assertEqual(len(a.quantum_connections), 2)
     a.remove_q_connection('B')
     self.assertEqual(len(a.classical_connections), 2)
     self.assertEqual(len(a.quantum_connections), 1)
     a.remove_c_connection('B')
     self.assertEqual(len(a.classical_connections), 1)
     self.assertEqual(len(a.quantum_connections), 1)
     a.remove_connection('C')
     self.assertEqual(len(a.classical_connections), 0)
     self.assertEqual(len(a.quantum_connections), 0)
     a.remove_connection('C')
     self.assertEqual(len(a.classical_connections), 0)
     self.assertEqual(len(a.quantum_connections), 0)
Ejemplo n.º 9
0
def main():
    network = Network.get_instance()
    network.start()
    network.delay = 0.2

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.add_connections(['Alice', 'Eve'])
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connections(['Bob', 'Dean'])
    host_eve.start()

    host_dean = Host('Dean')
    host_dean.add_connection('Eve')
    host_dean.start()

    network.add_hosts([host_alice, host_bob, host_eve, host_dean])

    print('alice sends message')
    host_alice.send_classical('Bob', 'hello1')
    host_alice.send_classical('Bob', 'hello2')
    host_alice.send_classical('Bob', 'hello3')
    host_alice.send_classical('Bob', 'hello4')
    host_alice.send_classical('Bob', 'hello5')
    host_alice.send_classical('Bob', 'hello6')
    host_alice.send_classical('Bob', 'hello7')
    host_alice.send_classical('Bob', 'hello8')
    host_alice.send_classical('Bob', 'hello9')
    host_alice.send_classical('Bob', 'hello10')

    start_time = time.time()
    while time.time() - start_time < 10:
        pass

    network.stop(True)
    exit()
Ejemplo n.º 10
0
Archivo: b92.py Proyecto: tqsd/QuNetSim
def main():

    intercept = True
    key_size = 100
    sample_len = int(key_size / 4)

    network = Network.get_instance()
    nodes = ['Alice', 'Eve', 'Bob']
    network.start(nodes)

    host_alice = Host('Alice')
    host_alice.add_connection('Eve')
    host_alice.start()

    host_eve = Host('Eve')
    host_eve.add_connections(['Alice', 'Bob'])
    host_eve.start()

    host_bob = Host('Bob')
    host_bob.add_connection('Eve')
    host_bob.delay = 0.5
    host_bob.start()

    network.add_host(host_alice)
    network.add_host(host_eve)
    network.add_host(host_bob)

    secret_key = np.random.randint(2, size=key_size)

    if intercept:
        host_eve.q_relay_sniffing = True
        host_eve.q_relay_sniffing_fn = eve_intercept_quantum

    t1 = host_alice.run_protocol(protocol_alice,
                                 (host_bob.host_id, secret_key, sample_len))
    t2 = host_bob.run_protocol(protocol_bob,
                               (host_alice.host_id, key_size, sample_len))

    t1.join()
    t2.join()
    network.stop(True)