cascade.block module

class cascade.block.Block(key, shuffle, start_index, end_index, parent_block)

Bases: object

A block is a contiguous subset of bits in a shuffled key.

ERRORS_EVEN = 0

The block contains an odd number of errors.

ERRORS_ODD = 1

The block contains an even number of errors.

ERRORS_UNKNOWN = None

We don’t know whether the block contains an even or an odd number of errors.

__init__(key, shuffle, start_index, end_index, parent_block)

Create a block, which is a contiguous subset of bits in a shuffled key.

Parameters
  • key (Key) – The key for which to create one single block that covers a subset of the key.

  • shuffle (Shuffle) – The shuffle to apply to the key before creating the block.

  • start_index (int) – The shuffle index, inclusive, at which the block starts. Must be in range [0, shuffle._size).

  • end_index (int) – The shuffle index, exclusive, at which the block end. Must be in range [0, shuffle._size]. The range must encompass at least 1 bit, i.e. end_index > start_index.

  • parent_block (Block) – The parent block. None if there is no parent, i.e. if this is a top-level block.

__repr__()

Get the unambiguous string representation of the block.

Returns

The unambiguous string representation of the block.

__str__()

Get the human-readable string representation of the block.

Returns

The human-readable string representation of the block.

static create_covering_blocks(key, shuffle, block_size)

Create a list of blocks of a given size that cover a given shuffled key.

Parameters
  • key (Key) – The key for which to create a list of block that collectively cover the entire key.

  • shuffle (Shuffle) – The shuffle to apply to the key before creating the blocks.

  • block_size (int) – The size of each block. Each block in the list, except for the last one, will be exactly this size. The last block may be smaller.

Returns

A list of blocks that cover the shuffled key.

create_left_sub_block()

Create the left sub-block of this block. If the block has an odd size, the left sub-block will be one bit larger than the right sub-block. The block must be at least 2 bits in size.

Returns

The left sub-block.

create_right_sub_block()

Create the right sub-block of this block. If the block has an odd size, the left sub-block will be one bit larger than the right sub-block. The block must be at least 2 bits in size.

Returns

The right sub-block.

flip_bit(flipped_shuffle_index)

Flip a bit in the block.

Params:

flipped_shuffle_index: The shuffle index of the bit to flip.

flip_parity()

Flip the current parity of this block. This is needed when a single bit in the block is flipped as a result of a single bit error correction.

get_correct_parity()

Get the correct parity of the block, if we know it.

Returns

The current parity (0 or 1) of the block, or None if we don’t know it.

get_current_parity()

Get the current parity of the block.

Returns

The current parity (0 or 1) of the block.

get_end_index()

Get the end index of the block, i.e. the shuffled key index for the first bit after the last bit in the block.

Returns

The end index.

get_error_parity()

Does this block have an odd or an even number of errors?

Returns

  • ERRORS_ODD = The block contains an odd number of errors.

  • ERRORS_EVEN = The block contains an even number of errors.

  • ERRORS_UNKNOWN = We don’t yet know whether the block contains an odd or even number of errors because we have not yet asked what the parity of the original key (witout noise) is.

get_key_index(shuffle_index)

The the key index that corresponds to a given shuffle index.

Params:

shuffle_index: The shuffle index.

Returns

The key index.

get_key_indexes()

Get a list of key indexes for this block.

Returns

The key indexes for this block (the ordering of the list is undefined; in particular don’t assume that the key indexes are in increasing order.)

get_left_sub_block()

Return the left sub-block of this block, if it has one.

Returns

The left sub-block, or None if there is no left sub-block.

get_parent_block()

Return the parent block of this block, if it has one.

Returns

The parent block, or None if there is no parent block.

get_right_sub_block()

Return the right sub-block of this block, if it has one.

Returns

The right sub-block, or None if there is no right sub-block.

get_shuffle()

Get the shuffle for this block.

Returns

The shuffle for this block.

get_size()

Get the size of the block in bits.

Returns

The size of the block in bits.

get_start_index()

Get the start index of the block, i.e. the shuffled key index for the first bit in the block.

Returns

The start index.

is_top_block()

Is this block a top-level block?

Returns

True if the block was created by splitting a shuffled key into blocks. False if the block was created by splitting a block into sub-blocks.

set_correct_parity(correct_parity)

Set the correct parity of the block.

Params:

correct_parity (int): The current parity (0 or 1).