QKDSimkit.core package
alice module
This module simulates Alice’s operations
bob module
This module simulates Bob’s operations
channel module
This module simulates channel’s operations
channel_features module
This module contains methods to simulate some feature of a channel
models module
This module simulates the behaviour of a photon
- class QKDSimkit.core.models.Photon[source]
Bases:
objectPhoton, it has bit, basis and polarization and some methods to manipulate them
- measure(polarization: int) int[source]
Give back a polarization according to the basis of the photon
- Parameters
polarization (int) – polarization
- Returns
polarization
node module
- class QKDSimkit.core.node.Node(ID, size)[source]
Bases:
objectFather class for receiver and sender
- Parameters
ID (str) – identifier of alice-bob pair
size (int) – size of key in bits
- Type
int
- Type
float
key with only common values
- Type
list
first half of the key
- Type
list
- Type
list
- connect_to_channel(address: str, port: int)[source]
It starts the connection with the channel
- Parameters
address (str) – address
port (int) – port
Converts the whole photon pulse in a list of bit
Create the part of the key that will be sent to the other node (first half)
- get_key()[source]
Create the part of the key that will not be sent and it will be used as symmetric key (second half)
- listen_for(sender: str, attr: str)[source]
Receive a message and store it in the right place
- Parameters
sender (str) – name of the node from which we expect to receive
attr (str) – name of the attribute that will store the content of the received message
- ownMessage(addr: str) bool[source]
Check if a message comes from this node
- Parameters
addr (str) – address of the received message
- recv_all() list[source]
receive a message receive from socket, sum every part of the message, check if the message is commplete, check if the ID of the sender corresponds to the ID of the receiver, return a list whit header and payload, please note that the ID is not returned
- Returns
list made by header and payload
- Return type
fragments (list)
qexceptions module
receiver module
- class QKDSimkit.core.receiver.Receiver(ID, size)[source]
Bases:
NodeReceiver class, it expands node, it contains methods to communicate a sender node, it can’t take action but it has to wait for the sender node for sending data, it can answer to a request with a message or to a message with an acknowledgement
- listen_quantum()[source]
Listen method to receive photon pulse it behaves like a wrapper for recv for photon pulses
- measure_photon_pulse()[source]
Measure photon pulse
given the vector that stores polarizations of received photons it creates a list of photons each polarization, basis and bit will be determined byt the measure method according to physical properties, a list with the basis of every photon will be stored
- recv(header: str) str[source]
Receive function for receiver node it listen for a message, in case the header of the received message doesn’t match it checks if an acknowledgment for the received message has been already sent or if the received message is an acknowledgement itself for a previously sent message, it sends a new acknowledgment in the first case and it sends again the message in the other case, if the message is new and the header is correct it sends an acknowledgement and it saves it
- Parameters
header (str) – unique identifier of the message that has to be received
- Returns
the payload of the received data, the header and some other infos are not returned
- Return type
message (str)
- send(header: str, message: str)[source]
Send method for receiver it listens for the request from the sender node, in case the header of the received message doesn’t match it checks if an acknowledgment for the received header has been already sent or if the message for the requested header has been already sent, it sends a new acknowledgement in the first case and it sends again the message in the other case, it sends the expected message if the header is correct, the sent message is saved in a list
- Parameters
header (str) – unique identifier
message (str) – message
sender module
- class QKDSimkit.core.sender.Sender(ID, size: int)[source]
Bases:
NodeSender class, it expands Node, it contains methods to communicate a receiver node, the general idea is that this node dictate the communication and the receiver can just answer
- generate_reconciled_key()[source]
Generate a common key between the two parties
it checks for every photon if the chosen basis is common, if it is not common the basis is discarded
- recv(header: str)[source]
Receiver method for sender node It will send a request message with the given header and it will wait for the response for a time timeout_in_seconds it may try multiple times depending on the variable connection_attempts, every received message with a different header will be discarded
- Parameters
header (str) – unique identifier
- send(header: str, message: str)[source]
Sender method for sender node it sends a message and wait for an acknowledgment if it doesn’t receive the ack in the given time timeout_in_seconds it may try multiple times depending on the variable connection_attempts
- Parameters
header (str) – unique identifier
message (str) – string to be sent
utils module
- QKDSimkit.core.utils.decrypt(token: bytes, message: str) str[source]
Decrypts a message using a given key
- Parameters
token (bytes) – key (32 url-safe base64-encoded bytes)
message (str) – encrypted message
- Returns
clear text message (str)
- QKDSimkit.core.utils.encrypt(token: bytes, message: str) str[source]
Encrypts a message using a given key
- Parameters
token (bytes) – key (32 url-safe base64-encoded bytes)
message (str) – clear text message
- Returns
encrypted message (str)