-
-

Protocols

+
+

Protocols

-
-components.protocols._decode_superdense(q1, q2)
+
+qunetsim.components.protocols._decode_superdense(q1, q2)

Return the message encoded into q1 with the support of q2.

-

Args: -q1: the qubit the message is encoded into -q1: the supporting entangled pair

-
Returns
-

A string of decoded message.

+
Parameters
+
    +
  • q1 (Qubit) – The qubit the message is encoded into

  • +
  • q1 – The supporting entangled pair

  • +
-
Return type
-

string

+
Returns
+

A string of decoded message.

+
+
Return type
+

(str)

-
-components.protocols._encode_superdense(message, q)
+
+qunetsim.components.protocols._encode_superdense(message, q)

Encode qubit q with the 2 bit message.

Parameters
@@ -237,13 +240,13 @@
-
-components.protocols._rec_classical(packet)
+
+qunetsim.components.protocols._rec_classical(packet)

Receives a classical message packet , parses it into sequence number and message and sends an ACK message to receiver.

Parameters
-

packet (Packet) – The packet in which to receive.

+

packet (Packet) – The packet in which to receive.

Returns

A dictionary consisting of ‘message’ and ‘sequence number’

@@ -255,13 +258,13 @@
-
-components.protocols._rec_epr(packet)
+
+qunetsim.components.protocols._rec_epr(packet)

Receives a classical message packet , parses it into sequence number and message and sends an ACK message to receiver.

Parameters
-

packet (Packet) – The packet in which to receive.

+

packet (Packet) – The packet in which to receive.

Returns

A dictionary consisting of ‘message’ and ‘sequence number’

@@ -273,29 +276,45 @@
-
-components.protocols._rec_ghz(packet)
+
+qunetsim.components.protocols._rec_ghz(packet)

Receives a GHZ state and stores it in quantum storage.

+
+
Parameters
+

packet (Packet) – The incoming packet

+
+
-
-components.protocols._rec_qubit(packet)
+
+qunetsim.components.protocols._rec_key(packet)
+

Receive a QKD key.

+
+
Parameters
+

packet (Packet) – The incoming packet

+
+
+
+ +
+
+qunetsim.components.protocols._rec_qubit(packet)

Receive a packet containing qubit information (qubit is transmitted externally)

Parameters
-

packet (Packet) – The packet in which to receive.

+

packet (Packet) – The packet in which to receive.

-
-components.protocols._rec_superdense(packet)
+
+qunetsim.components.protocols._rec_superdense(packet)

Receives a superdense qubit and decodes it.

Parameters
-

packet (Packet) – The packet in which to receive.

+

packet (Packet) – The packet in which to receive.

Returns

A dictionary consisting of decoded superdense message and sequence number

@@ -307,32 +326,32 @@
-
-components.protocols._rec_teleport(packet)
+
+qunetsim.components.protocols._rec_teleport(packet)

Receives a classical message and applies the required operations to EPR pair entangled with the sender to retrieve the teleported qubit.

Parameters
-

packet (Packet) – The packet in which to receive.

+

packet (Packet) – The packet in which to receive.

-
-components.protocols._relay_message(packet)
+
+qunetsim.components.protocols._relay_message(packet)

Reduce TTL of network packet and if TTL > 0, sends the message to be relayed to the next node in the network and modifies the header.

Parameters
-

packet (RoutingPacket) – Packet to be relayed

+

packet (RoutingPacket) – Packet to be relayed

-
-components.protocols._send_ack(sender, receiver, seq_number)
+
+qunetsim.components.protocols._send_ack(sender, receiver, seq_number)

Send an acknowledge message from the sender to the receiver. :param sender: The sender ID :type sender: str @@ -343,67 +362,72 @@

-
-components.protocols._send_classical(packet)
+
+qunetsim.components.protocols._send_classical(packet)

Sends a classical message to another host.

Parameters
-

packet (Packet) – The packet in which to transmit.

+

packet (Packet) – The packet in which to transmit.

-
-components.protocols._send_epr(packet)
+
+qunetsim.components.protocols._send_epr(packet)

Sends an EPR to another host in the network.

Parameters
-

packet (Packet) – The packet in which to transmit.

+

packet (Packet) – The packet in which to transmit.

-
-components.protocols._send_ghz(packet)
+
+qunetsim.components.protocols._send_ghz(packet)

Gets GHZ qubits and distributes the to all hosts. One qubit is stored in own storage.

+
+
Parameters
+

packet (Packet) – The incoming packet

+
+
-
-components.protocols._send_qubit(packet)
+
+qunetsim.components.protocols._send_qubit(packet)

Transmit the qubit :param packet: The packet in which to transmit. :type packet: Packet

-
-components.protocols._send_superdense(packet)
+
+qunetsim.components.protocols._send_superdense(packet)

Encodes and sends a qubit to send a superdense message.

Parameters
-

packet (Packet) – The packet in which to transmit.

+

packet (Packet) – The packet in which to transmit.

-
-components.protocols._send_teleport(packet)
+
+qunetsim.components.protocols._send_teleport(packet)

Does the measurements for teleportation of a qubit and sends the measurement results to another host.

Parameters
-

packet (Packet) – The packet in which to transmit.

+

packet (Packet) – The packet in which to transmit.

-
-components.protocols.encode(sender, receiver, protocol, payload=None, payload_type='', sequence_num=-1, await_ack=False)
+
+qunetsim.components.protocols.encode(sender, receiver, protocol, payload=None, payload_type='', sequence_num=-1, await_ack=False)

Encodes the data with the sender, receiver, protocol, payload type and sequence number and forms the packet with data and the header. :param sender: ID of the sender @@ -424,18 +448,18 @@

Encoded packet

Return type
-

(Packet)

+

(Packet)

-
-components.protocols.process(packet)
+
+qunetsim.components.protocols.process(packet)

Decodes the packet and processes the packet according to the protocol in the packet header.

Parameters
-

packet (Packet) – Packet to be processed.

+

packet (Packet) – Packet to be processed.

Returns

Returns what protocol function returns.

diff --git a/docs/_build/examples/QKD.html b/docs/_build/examples/QKD.html index 0c738ef1..57e66193 100644 --- a/docs/_build/examples/QKD.html +++ b/docs/_build/examples/QKD.html @@ -241,7 +241,7 @@

Quantum Key Distribution
import numpy as np
+35
import numpy as np
 
 # Initialize a network
 network = Network.get_instance()
@@ -372,9 +372,9 @@ 

Quantum Key Distributionsequence_nr = 0 # iterate over all bits in the secret key. for bit in secret_key: - ack = False + ack = False while not ack: - print("Alice sent %d key bits" % (sequence_nr + 1)) + print("Alice sent %d key bits" % (sequence_nr + 1)) # get a random base. 0 for Z base and 1 for X base. base = random.randint(0, 1) @@ -390,7 +390,7 @@

Quantum Key Distributionq_bit.H() # Send Qubit to Bob - alice.send_qubit(receiver, q_bit, await_ack=True) + alice.send_qubit(receiver, q_bit, await_ack=True) # Get measured basis of Bob message = alice.get_next_classical_message(receiver, msg_buff, sequence_nr) @@ -398,11 +398,11 @@

Quantum Key Distribution# Compare to send basis, if same, answer with 0 and set ack True and go to next bit, # otherwise, send 1 and repeat. if message == ("%d:%d") % (sequence_nr, base): - ack = True - alice.send_classical(receiver, ("%d:0" % sequence_nr), await_ack=True) + ack = True + alice.send_classical(receiver, ("%d:0" % sequence_nr), await_ack=True) else: - ack = False - alice.send_classical(receiver, ("%d:1" % sequence_nr), await_ack=True) + ack = False + alice.send_classical(receiver, ("%d:1" % sequence_nr), await_ack=True) sequence_nr += 1 @@ -417,7 +417,7 @@

Quantum Key Distribution# wait for the qubit q_bit = eve.get_data_qubit(sender, wait=wait_time) - while q_bit is None: + while q_bit is None: q_bit = eve.get_data_qubit(sender, wait=wait_time) # measure qubit in right measurement basis @@ -426,7 +426,7 @@

Quantum Key Distributionbit = q_bit.measure() # Send Alice the base in which Bob has measured - eve.send_classical(sender, "%d:%d" % (sequence_nr, measurement_base), await_ack=True) + eve.send_classical(sender, "%d:%d" % (sequence_nr, measurement_base), await_ack=True) # get the return message from Alice, to know if the bases have matched msg = eve.get_next_classical_message(sender, msg_buff, sequence_nr) @@ -434,7 +434,7 @@

Quantum Key Distribution# Check if the bases have matched if msg == ("%d:0" % sequence_nr): received_counter += 1 - print("Eve received %d key bits." % received_counter) + print("Eve received %d key bits." % received_counter) key_array.append(bit) sequence_nr += 1 @@ -472,7 +472,7 @@

Quantum Key Distributionreturn encrypt(key, encrypted_text) # Test the encryption algorithm -print(decrypt('a', decrypt('a', "Encryption works!"))) +print(decrypt('a', decrypt('a', "Encryption works!")))

Alice can finally send her message to Eve, without being disturbed by Bob!

@@ -505,8 +505,8 @@

Quantum Key Distributionmsg_to_eve = "Hi Eve, how are you???" secret_key_string = key_array_to_key_string(secret_key) encrypted_msg_to_eve = encrypt(secret_key_string, msg_to_eve) - print("Alice sends encrypted message") - alice.send_classical(receiver, "-1:" + encrypted_msg_to_eve, await_ack=True) + print("Alice sends encrypted message") + alice.send_classical(receiver, "-1:" + encrypted_msg_to_eve, await_ack=True) def eve_receive_message(eve, msg_buff, eve_key, sender): @@ -514,7 +514,7 @@

Quantum Key Distributionencrypted_msg_from_alice = encrypted_msg_from_alice.split(':')[1] secret_key_string = key_array_to_key_string(eve_key) decrypted_msg_from_alice = decrypt(secret_key_string, encrypted_msg_from_alice) - print("Eve received decoded message: %s" % decrypted_msg_from_alice) + print("Eve received decoded message: %s" % decrypted_msg_from_alice)