def main(): network = Network.get_instance() backend = EQSNBackend() number_of_entanglement_pairs = 50 nodes = ['A', 'B'] 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_connection('A') host_B.delay = 0 host_B.start() network.add_host(host_A) network.add_host(host_B) t1 = host_A.run_protocol(alice, (host_B.host_id, number_of_entanglement_pairs)) t2 = host_B.run_protocol(bob, (host_A.host_id, number_of_entanglement_pairs)) t1.join() t2.join() network.stop(True)
def main(): network = Network.get_instance() nodes = ["Alice", "Bob"] network.x_error_rate = 0 network.delay = 0.5 network.start(nodes) host_alice = Host('Alice') host_alice.add_connection('Bob') host_alice.max_ack_wait = 10 host_alice.delay = 0.2 host_alice.start() host_bob = Host('Bob') host_bob.max_ack_wait = 10 host_bob.delay = 0.2 host_bob.add_connection('Alice') host_bob.start() network.add_host(host_alice) network.add_host(host_bob) q_size = 6 host_alice.run_protocol(qudp_sender, (q_size, host_bob.host_id)) host_bob.run_protocol(qudp_receiver, (q_size, host_alice.host_id)) start_time = time.time() while time.time() - start_time < 50: pass network.stop(stop_hosts=True)
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)
def setup_network(): network = Network.get_instance() network.start() network.delay = 0.0 host_A = Host('A') host_A.add_connection('B') host_A.delay = 0 host_A.start() host_B = Host('B') host_B.add_connection('C') host_B.add_connection('A') host_B.delay = 0 host_B.start() host_C = Host('C') 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) return network, host_A, host_B, host_C
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
def main(): # Initialize a network network = Network.get_instance() backend = EQSNBackend() # Define the host IDs in the network nodes = ['Alice', 'Bob'] network.delay = 0.0 # Start the network with the defined hosts network.start(nodes, backend) # Initialize the host Alice host_alice = Host('Alice', backend) # Add a one-way connection (classical and quantum) to Bob host_alice.add_connection('Bob') host_alice.delay = 0.0 # Start listening host_alice.start() host_bob = Host('Bob', backend) # Bob adds his own one-way connection to Alice host_bob.add_connection('Alice') host_bob.delay = 0.0 host_bob.start() # Add the hosts to the network # The network is: Alice <--> Bob network.add_host(host_alice) network.add_host(host_bob) # Generate random key key_size = 20 # the size of the key in bit secret_key = np.random.randint(2, size=key_size) # Concatentate functions def alice_func(alice): msg_buff = [] alice_qkd(alice, msg_buff, secret_key, host_bob.host_id) alice_send_message(alice, secret_key, host_bob.host_id) def bob_func(eve): msg_buff = [] eve_key = eve_qkd(eve, msg_buff, key_size, host_alice.host_id) eve_receive_message(eve, msg_buff, eve_key, host_alice.host_id) # Run Bob and Alice t1 = host_alice.run_protocol(alice_func, ()) t2 = host_bob.run_protocol(bob_func, ()) t1.join() t2.join() network.stop(True)
def main(): network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes) network.delay = 0.5 host_alice = Host('Alice') host_alice.add_connection('Bob') host_alice.max_ack_wait = 30 host_alice.delay = 0.2 host_alice.start() host_bob = Host('Bob') host_bob.max_ack_wait = 30 host_bob.delay = 0.2 host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.start() host_eve = Host('Eve') host_eve.max_ack_wait = 30 host_eve.delay = 0.2 host_eve.add_connection('Bob') host_eve.add_connection('Dean') host_eve.start() host_dean = Host('Dean') host_dean.max_ack_wait = 30 host_dean.delay = 0.2 host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) network.x_error_rate = 0 network.packet_drop_rate = 0 q_size = 6 checksum_per_qubit = 2 host_alice.run_protocol(checksum_sender, (q_size, host_dean.host_id, checksum_per_qubit)) host_dean.run_protocol(checksum_receiver, (q_size, host_alice.host_id, checksum_per_qubit)) start_time = time.time() while time.time() - start_time < 150: pass network.stop(stop_hosts=True) exit()
def main(): global thread_1_return global thread_2_return network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes) network.delay = 0.5 host_alice = Host('alice') host_alice.add_connection('bob') host_alice.max_ack_wait = 30 host_alice.delay = 0.2 host_alice.start() host_bob = Host('bob') host_bob.max_ack_wait = 30 host_bob.delay = 0.2 host_bob.add_connection('alice') host_bob.add_connection('eve') host_bob.start() host_eve = Host('eve') host_eve.max_ack_wait = 30 host_eve.delay = 0.2 host_eve.add_connection('bob') host_eve.add_connection('dean') host_eve.start() host_dean = Host('dean') host_dean.max_ack_wait = 30 host_dean.delay = 0.2 host_dean.add_connection('eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) host_alice.run_protocol(retransmission_sender, (host_dean.host_id, MAX_TRIAL_NUM)) host_dean.run_protocol(retransmission_receiver, (host_alice.host_id, MAX_TRIAL_NUM)) start_time = time.time() while time.time() - start_time < 150: pass network.stop(stop_hosts=True) exit()
def main(): # Initialize a network network = Network.get_instance() nodes = ['Bank', 'Customer', 'Eve'] network.delay = 0.2 network.start(nodes) host_bank = Host('Bank') host_bank.add_connection('Eve') host_bank.delay = 0.3 host_bank.start() host_eve = Host('Eve') host_eve.add_connection('Bank') host_eve.add_connection('Customer') host_eve.start() host_customer = Host('Customer') host_customer.add_connection('Eve') host_customer.delay = 0.3 host_customer.start() network.add_host(host_bank) network.add_host(host_eve) network.add_host(host_customer) host_eve.q_relay_sniffing = True host_eve.q_relay_sniffing_fn = sniffing_quantum print('Starting transfer') t = host_customer.run_protocol(customer_protocol, (host_bank.host_id, )) host_bank.run_protocol(banker_protocol, (host_customer.host_id, ), blocking=True) t.join() network.stop(True)
def main(): network = Network.get_instance() # backend = ProjectQBackend() # backend = CQCBackend() backend = EQSNBackend() nodes = ['A', 'B'] network.delay = 0.1 network.start(nodes, backend) 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_connection('A') host_B.delay = 0 host_B.start() network.add_host(host_A) network.add_host(host_B) m = 2 n = 4 rot_angle = np.pi / 9 t1 = host_A.run_protocol(quantum_coin_flipping, arguments=(m, n, host_B.host_id, rot_angle)) t2 = host_B.run_protocol(quantum_coin_flipping, arguments=(m, n, host_A.host_id, rot_angle)) t1.join() t2.join() network.stop(True)
def setup_network(num_hosts, backend): network = Network.get_instance() network.start(nodes=[str(i) for i in range(num_hosts)], backend=backend) network.delay = 0.0 hosts = [] for i in range(num_hosts): h = Host(str(i), backend=backend) h.delay = 0 h.start() if i < num_hosts - 1: h.add_connection(str(i + 1)) if i > 0: h.add_connection(str(i - 1)) hosts.append(h) network.add_hosts(hosts) return network, hosts
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)
def main(): global thread_1_return global thread_2_return network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] back = CQCBackend() network.start(nodes, back) network.delay = 0.0 host_alice = Host('Alice', back) host_alice.add_connection('Bob') host_alice.max_ack_wait = 30 host_alice.delay = 0.0 host_alice.start() host_bob = Host('Bob', back) host_bob.max_ack_wait = 30 host_bob.delay = 0.0 host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.start() host_eve = Host('Eve', back) host_eve.max_ack_wait = 30 host_eve.delay = 0.0 host_eve.add_connection('Bob') host_eve.add_connection('Dean') host_eve.start() host_dean = Host('Dean', back) host_dean.max_ack_wait = 30 host_dean.delay = 0.0 host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) network.x_error_rate = 0 network.packet_drop_rate = 0 q_size = 6 checksum_per_qubit = 2 host_alice.run_protocol(qtcp_sender, (q_size, host_dean.host_id, checksum_per_qubit)) host_dean.run_protocol(qtcp_receiver, (q_size, host_alice.host_id, checksum_per_qubit)) while thread_1_return is None or thread_2_return is None: if thread_1_return is False or thread_2_return is False: print('TCP Connection not successful : EXITING') sys.exit(1) pass start_time = time.time() while time.time() - start_time < 150: pass network.stop(stop_hosts=True) exit()
def main(): network = Network.get_instance() network.start() network.delay = 0.0 host_A = Host('A') host_A.add_c_connection('C') host_A.delay = 0 host_A.start() host_B = Host('B') host_B.add_c_connection('C') host_B.delay = 0 host_B.start() host_C = Host('C') host_C.add_c_connections(['A', 'B']) host_C.delay = 0 host_C.start() network.add_host(host_C) # To generate entanglement host_A.add_connection('B') host_B.add_connection('A') network.add_host(host_A) network.add_host(host_B) # strategy = 'CLASSICAL' strategy = 'QUANTUM' host_A.delay = 0.0 host_B.delay = 0.0 host_C.delay = 0.0 print('Starting game. Strategy: %s' % strategy) if strategy == 'QUANTUM': print('Generating initial entanglement...') for i in range(PLAYS): host_A.send_epr('B', await_ack=True) print('created %d EPR pairs' % (i + 1)) print('Done generating initial entanglement') else: network.delay = 0.0 network.draw_classical_network() # Remove the connection from Alice and Bob host_A.remove_connection('B') host_B.remove_connection('A') # Play the game classically if strategy == 'CLASSICAL': host_A.run_protocol(alice_classical, (host_C.host_id, )) host_B.run_protocol( bob_classical, (host_C.host_id, ), ) # Play the game quantumly if strategy == 'QUANTUM': host_A.run_protocol(alice_quantum, (host_C.host_id, host_B.host_id)) host_B.run_protocol(bob_quantum, (host_C.host_id, host_A.host_id)) host_C.run_protocol(referee, (host_A.host_id, host_B.host_id), blocking=True) network.stop(True) # network.draw_quantum_network() network.draw_classical_network()