utils.utils module
Useful functions for creating encryption schemes.
- utils.utils.extended_euclidean(num_a, num_b)[source]
Perform the extended euclidean algorithm on the input numbers. The method returns gcd, x, y, such that a*x + b*y = gcd.
- Parameters:
num_a (
int
) – First number a.num_b (
int
) – Second number b.
- Return type:
Tuple
[int
,int
,int
]- Returns:
Tuple containing gcd, x, and y, such that a*x + b*y = gcd.
- utils.utils.lcm(num_a, num_b)[source]
Compute the least common multiple of two input numbers. Uses GMPY2 if available.
- Parameters:
num_a (
int
) – First number a.num_b (
int
) – Second number b.
- Return type:
int
- Returns:
Least common multiple of a and b.
- utils.utils.mod_inv(value, modulus)[source]
Compute the inverse of a number, given the modulus of the group. Note that the inverse might not exist. Uses GMPY2 if available.
- Parameters:
value (
int
) – The number to be inverted.modulus (
int
) – The group modulus.
- Raises:
ZeroDivisionError – Raised when the inverse of the value does not exist.
- Return type:
int
- Returns:
The inverse of a under the modulus.