Esempio n. 1
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
Esempio n. 2
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()
Esempio n. 3
0
File: b92.py Progetto: 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)
Esempio n. 4
0
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)