cascade.key module

class cascade.key.Key

Bases: object

A key that the Cascade protocol reconciles.

ERROR_METHODS = ['bernoulli', 'exact']
ERROR_METHOD_BERNOULLI = 'bernoulli'
ERROR_METHOD_EXACT = 'exact'
__init__()

Create an empty key.

__repr__()

Get the unambiguous string representation of the key.

Returns

The unambiguous string representation of the key.

__str__()

Get the human-readable string representation of the key.

Returns

The human-readable string representation of the key.

copy(error_rate, error_method)

Copy a key and optionally apply noise.

Parameters
  • error_rate (float) – The requested error rate.

  • error_method (str) – The method for choosing errors. Must be one of the error methods in ERROR_METHODS.

Returns

A new Key instance, which is a copy of this key, with noise applied.

static create_random_key(size)

Create an random key.

Parameters

size (int) – The size of the key in bits. Must be >= 0.

Returns

A random key of the specified size.

difference(other_key)

Return the number of bits that are different between this key and the other_key (also known as the Hamming distance).

Parameters

other_key (Key) – The other key that this key has to be compared with. Must be the same size as this key.

Returns

The number of bits that are different between this key and the other key.

flip_bit(index)

Flip the value of the key bit at a given index (0 to 1, and vice versa).

Parameters

index (int) – The index of the bit. Index must be in range [0, key.size).

get_bit(index)

Get the value of the key bit at a given index.

Parameters

index (int) – The index of the bit. Index must be in range [0, key.size).

Returns

The value (0 or 1) of the key bit at the given index.

get_size()

Get the size of the key in bits.

Returns

The size of the key in bits.

set_bit(index, value)

Set the value of the key bit at a given index.

Parameters
  • index (int) – The index of the bit. Index must be in range [0, key.size).

  • value (int) – The new value of the bit. Must be 0 or 1.

static set_random_seed(seed)

Set the seed for the isolated random number generated that is used only in the key module and nowhere else. If two applications set the seed to the same value, the key module produces the exact same sequence of random keys. This is used to make experiments reproduceable.

Parameters

seed (int) – The seed value for the random number generator which is isolated to the key module.