utilities.py
Utilities
These are the common functions needed across all ciphers.
- urca.cpu.utilities.get_bits(values: tuple[int], value_size: int) tuple[tuple[int], ...]
Return the bit representation of the values.
- Parameters:
values (tuple[int]) – integers whose bit representation is needed
value_size (int) – the bit size for each integer
- Returns:
a tuple whose size is (len(values), value_size)
- Return type:
tuple[tuple[int], …]
Examples
>>> from urca.utilities import get_bits >>> get_bits((0x6, 0xA, 0x1, 0xA), 4) ((0, 1, 1, 0), (1, 0, 1, 0), (0, 0, 0, 1), (1, 0, 1, 0))
- urca.cpu.utilities.get_dtype(word_size: int) dtype
Return the minimum size dtype.
This function returns the minimum size dtype object that can contain the word size. This is useful for those ciphers having a non-power-of-2 word size (e.g. Speck 48/96).
- Parameters:
word_size (int) – the size of the word in bits
- Returns:
the numpy dtype object of the minimum size
- Return type:
np.dtype
Examples
>>> from urca.utilities import get_dtype >>> get_dtype(24) dtype('uint32')