helper¶
- class cryptographic_estimators.helper.ComplexityType(value)¶
Bases:
Enum
Distinguish between normal optimisation and tilde O optimisation.
- ESTIMATE = 0¶
- TILDEO = 1¶
- cryptographic_estimators.helper.concat_all_tables(tables)¶
Concatenates all tables in a list into a single PrettyTable object.
- Parameters:
tables (list) – List of PrettyTable objects.
- cryptographic_estimators.helper.concat_pretty_tables(t1: str, t2: str)¶
Merge two columns into one.
- Parameters:
t1 (str) – First column
t2 (str) – Second column
- cryptographic_estimators.helper.gf_order_to_characteristic(q)¶
Returns the characteristic of the Galois field GF(q) where q is the number of elements.
- Parameters:
q – A prime power representing the number of elements in the Galois field.
Examples
>>> from cryptographic_estimators.helper import gf_order_to_characteristic >>> gf_order_to_characteristic(7) 7
- Tests:
>>> gf_order_to_characteristic(11**3) 11
>>> gf_order_to_characteristic(10**3) Traceback (most recent call last): ... ValueError: q must be a prime power.
- cryptographic_estimators.helper.gf_order_to_degree(q)¶
Returns the degree of the Galois field GF(q) where q is the number of elements.
- Parameters:
q – A prime power representing the number of elements in the Galois field.
Examples
>>> from cryptographic_estimators.helper import gf_order_to_degree >>> gf_order_to_degree(3**2) 2
- Tests:
>>> gf_order_to_degree(127**4) 4
>>> gf_order_to_degree(10**3) Traceback (most recent call last): ... ValueError: q must be a prime power.
- cryptographic_estimators.helper.is_power_of_two(n)¶
Determines if a given number is a power of two.
- Parameters:
n – The number to be checked.
Examples
>>> from cryptographic_estimators.helper import is_power_of_two >>> is_power_of_two(16) True
- Tests:
>>> is_power_of_two(2**15) True
>>> is_power_of_two(21) False
- cryptographic_estimators.helper.is_prime_power(n, return_pair=False)¶
Determines if a given number is a power of a prime number.
- Parameters:
n – The number to be checked.
return_pair (bool) – Whether to return a pair or not. Defaults to False.
- Returns:
int, b:int)) where, if boolean is true, the input number is of the form a^b. Otherwise only returns the boolean.
- Return type:
If return_pair is True, a tuple (boolean, (a
Examples
>>> from cryptographic_estimators.helper import is_prime_power >>> is_prime_power(11) True
>>> is_prime_power(7**3, return_pair = True) (True, (7, 3))
- Tests:
>>> is_prime_power(101**2) True
>>> is_prime_power(7**3+1) False
>>> is_prime_power(1121) False
>>> is_prime_power(1087*1091) False
- cryptographic_estimators.helper.ngates(q, n, theta=2)¶
Returns the number of gates for the given number of multiplications in a finite field.
- Parameters:
q (int) – The order of the finite field.
n (int) – The number of multiplications (logarithmic).
theta (int) – The exponent of the conversion factor (default: 2).
Examples
>>> from cryptographic_estimators.helper import ngates >>> ngates(16, 16) 20.0
- Tests:
>>> ngates(6, 2**16) Traceback (most recent call last): ... ValueError: q must be a prime power
- cryptographic_estimators.helper.round_or_truncate(x: float, truncate: bool, precision: int)¶
Either rounds or truncates x if truncate is true.
- Parameters:
x (float) – Value to either truncate or round
truncate (bool) – If true: x will be truncated else rounded
precision (int) – Number of decimal digits