qkd_key_rate.protocols.classical package
Classical protocols
- class qkd_key_rate.protocols.classical.CascadeCorrector(alice, bob)[source]
Bases:
Corrector
Cascade corrector
- class qkd_key_rate.protocols.classical.CascadeReceiver(message, permutations, parity_strategy, name=None)[source]
Bases:
CascadeSender
,ReceiverBase
This class encodes all functions only available to the receiver.
The receiver is assumed to have a string with errors and is thus assumed to correct the errors.
- __init__(message, permutations, parity_strategy, name=None)[source]
- Parameters:
message (
Message
) – Input message of the sender partypermutations (
Permutations
) – List containing permutations for each Cascade passname (
Optional
[str
]) – Name of the receiver party
- check_match_of_parities(alice, current_pass, current_block, block_size)[source]
Checks if the parity strings of alice and bob match.
This requires communication between the two parties. The parities of multiple blocks can be combined in a single message.
- Parameters:
current_pass (
int
) – Index of current passcurrent_block (
int
) – Index of current blockalice (
CascadeSender
) – The sending party
- Return type:
bool
- Returns:
Boolean if the parity strings of alice and bob match
- correct_errors(alice)[source]
This is the main routine Errors in the strings alice and bob are found and corrected
An upper bound on the number of communications is estimated. This is however a loose upper bound. The cascade-routine makes it difficult to give tighter bounds
- Parameters:
alice (
SenderBase
) – The sending party to correct errors with- Return type:
None
- do_cascade(current_pass, current_block, block_size, alice, size_blocks_parities)[source]
Apply the Cascade error correction technique.
This routine corrects errors in previous passes that become apparent later. It is recursively used as long as new errors are found.
- Parameters:
current_pass (
int
) – Index of current passcurrent_block (
int
) – Index of current blockblock_size (
int
) – Size of current blockalice (
CascadeSender
) – The sending partysize_blocks_parities (
Tuple
[Tuple
[int
,int
],...
]) – For each pass the size of the block and number of blocks
- Return type:
None
- get_block_index(index, block_size, index_pass)[source]
Returns the block index corresponding to a certain index in a certain pass
- Parameters:
index (
int
) – Index of a certain bitblock_size (
int
) – Size of current blockindex_pass (
int
) – Index of the current pass
- Return type:
int
- Returns:
The block index corresponding to a certain bit index in a certain pass
- get_error_index(index_block, index_pass, block_size, alice)[source]
Recursively checks the parity of half of the block of both parties.
- Parameters:
index_block (
int
) – Index of the block in which we expect an errorindex_pass (
int
) – Index of the current passblock_size (
int
) – Size of current blockalice (
CascadeSender
) – The sending party
- Return type:
int
- Returns:
The position index of an error
- get_prior_error_rate(alice, index_start=0, index_finish=None)[source]
Determine the initial error rate. This function is mainly for debugging purposes. Usually, the considered bits are private and this value cannot be computed.
- Parameters:
alice (
CascadeSender
) – The sending partyindex_start (
int
) – Start index of the messageindex_finish (
Optional
[int
]) – End index of the message
- Return type:
float
- Returns:
Initial error rate
- class qkd_key_rate.protocols.classical.CascadeSender(message, permutations, name=None)[source]
Bases:
SenderBase
This class encodes all functions available to both sender and receiver for the Cascade protocol.
- __init__(message, permutations, name=None)[source]
- Parameters:
message (
Message
) – Input message of the sender partypermutations (
Permutations
) – List containing permutations for each Cascade passname (
Optional
[str
]) – Name of the sender party
- build_parity_string(block_size, pass_number)[source]
Built a string of parities for the given block size.
- Parameters:
block_size (
int
) – Message block sizepass_number (
int
) – Cascade permutation number
- Return type:
None
- get_parity(index_start, index_end, pass_number)[source]
Get the parity of a specific message block, taking into account the permutation applied in that specific pass.
- Parameters:
index_start (
int
) – Start index of the messageindex_end (
int
) – End index of the messagepass_number (
int
) – Cascade pass number
- Return type:
int
- Returns:
Parity of substring
- class qkd_key_rate.protocols.classical.PrivacyAmplification(observed_pulses_basis_x, error_rate_basis_x)[source]
Bases:
object
The privacy amplification module. A hash of an error corrected string is computed and returned. The length of the hashed string equals the remaining entropy.
- __init__(observed_pulses_basis_x, error_rate_basis_x)[source]
- Parameters:
observed_pulses_basis_x (
int
) – Number of pulses received in the X-basiserror_rate_basis_x (
float
) – Error rate in the pulses received in the X-basis
- do_hash(message, entropy)[source]
Computes the hash given a message of bits.
The length of the hash equals the secure entropy we have.
- Return type:
bytes
- get_entropy_estimate(error_correction_loss=0)[source]
Estimate the amount of entropy.
Uses the key-rate estimation functions to determine the key-rate and obtains the number of secure bits by multiplying this by the number of pulses sent. Adjusts the remaining entropy for losses due to the error-correction.
- Parameters:
error_correction_loss (
int
) – Number of corrected errors- Return type:
float
- Returns:
The amount of entropy
- class qkd_key_rate.protocols.classical.WinnowCorrector(alice, bob)[source]
Bases:
Corrector
Winnow corrector
- class qkd_key_rate.protocols.classical.WinnowReceiver(message, permutations, schedule, name=None)[source]
Bases:
WinnowSender
,ReceiverBase
This class encodes all functions only available to the receiver.
The receiver is assumed to have a string with errors and is thus assumed to correct the errors.
- __init__(message, permutations, schedule, name=None)[source]
- Parameters:
message (
Message
) – Input message of the sender partypermutations (
Permutations
) – List containing permutations for each passname (
Optional
[str
]) – Name of the receiver party
- correct_errors(alice)[source]
The main routine, finds all errors and corrects them.
It is assumed that Alice and Bob use one communication round to agree on the used permutations. Afterwards, they use two communication rounds per iteration to communicate the syndromes.
- Parameters:
alice (
WinnowSender
) – The sending party- Return type:
None
- fix_errors_with_syndrome(alice)[source]
Corrects errors using the syndrome strings of alice and bob
- Parameters:
alice (
WinnowSender
) – The sending party- Return type:
None
- class qkd_key_rate.protocols.classical.WinnowSender(message, permutations, schedule, name=None)[source]
Bases:
SenderBase
This class encodes all functions available to both sender and receiver.
It keeps track of the number of exposed bits and can compute syndromes and parities. Furthermore, it keeps track of the blocks with errors
- __init__(message, permutations, schedule, name=None)[source]
- Parameters:
message (
Message
) – Input message of the sender partypermutations (
Permutations
) – List containing permutations for each passname (
Optional
[str
]) – Name of the sender party
- build_syndrome_string(alice)[source]
Create a syndrome string for all disagreeing blocks.
Computes the syndrome for blocks with disagreeing parity.
- Parameters:
alice (
WinnowSender
) – The sending party- Return type:
None
- create_parity_check_matrix()[source]
Creates a parity check matrix.
This matrix is used to encode the bit strings.
- Return type:
None
- disagreeing_block_parities(alice)[source]
Finds the disagreeing block parities.
The found parities of both parties are compared. This can be done with two communication rounds (one both ways). Afterwards, both separately process the results.
- Parameters:
alice (
WinnowSender
) – The sending party- Return type:
None
- discard_syndrome_bits()[source]
Discards syndrome bits. Bits at indices \(2^j-1\) are removed. These correspond to the linearly independent columns of the parity check matrix.
In this function the number of bad blocks is known.
No communication is needed to discard syndrome bits.
- Return type:
None
- get_parity(index_start, index_end)[source]
Get the parity of a specific message part between two indices.
- Parameters:
index_start (
int
) – Start index of the messageindex_end (
int
) – End index of the message
- Return type:
int
- Returns:
Parity of substring
- get_syndrome(index_block)[source]
Computes the syndrome of a block.
Both parties compute their syndrome individually, hence, no communication is needed here.
- Return type:
int
- qkd_key_rate.protocols.classical.cascade module
- qkd_key_rate.protocols.classical.privacy_amplification module
- qkd_key_rate.protocols.classical.winnow module
WinnowCorrector
WinnowCorrectorOutput
WinnowReceiver
WinnowSender
WinnowSender.__init__()
WinnowSender.build_parity_string()
WinnowSender.build_syndrome_string()
WinnowSender.create_parity_check_matrix()
WinnowSender.disagreeing_block_parities()
WinnowSender.discard_parity_bits()
WinnowSender.discard_syndrome_bits()
WinnowSender.first_pass()
WinnowSender.get_parity()
WinnowSender.get_syndrome()
WinnowSender.next_pass()
WinnowSender.permute_buffer()