Utils#

Cryption#

crypton.utils.cryption.apply_func_to_char(c: int, f: Callable, mod: int = 26) int#

Applies function to given char in int form, takes the modulus with given mod and returns the result

Parameters
  • c (int) – Char in int form

  • f (Function) – Function to apply

  • mod (int) – Modulus space

Returns

Function applied character

Return type

int

crypton.utils.cryption.encrypt_decrypt_helper(plain_text: str, a: int, b: int, f: Callable, space: str) str#

Because of the similarity between encrypt & decrypt operations, this function applies the given function f and does affine encryption

Parameters
  • plain_text (str) – Text we want to encrypt/decrypt

  • a (int) – An integer that corresponds to the A parameter in affine cypher

  • b (int) – An integer that corresponds to the B parameter in affine cypher

  • f (Function) – Function to apply, this parameter decides if we’re going to encrypt or decrypt

  • space (str) – Target space

Returns

Encrypted/decrypted text

Return type

str

crypton.utils.cryption.get_pairs_of_int_two_from_text(text: str, space: str) List[List[int]]#

Creates pairs of two from the given text

Parameters
  • text (str) – Text we want to create pairs from

  • space (str) – Target space

Returns

Pairs of two in list form

Return type

List(List(int))

Math#

crypton.utils.math.add_matrices_and_flatten(a: numpy.ndarray, b: numpy.ndarray) List[int]#
crypton.utils.math.apply_function_and_flatten_matrices(a: numpy.ndarray, b: numpy.ndarray, function: Callable) List[int]#
crypton.utils.math.create_nested_list_from_flat_list(flat_list: List[int]) List[List[int]]#
crypton.utils.math.det(matrix: numpy.ndarray) int#
crypton.utils.math.dot_product_with_multiple_matrices(matrices: List[numpy.ndarray]) numpy.ndarray#
crypton.utils.math.get_inverse_matrix(matrix: numpy.ndarray) List#
crypton.utils.math.get_reverse_modulus(number: int, mod: int = 26) int#
crypton.utils.math.inverse_matrix(matrix: numpy.ndarray) List#
crypton.utils.math.modulo(number: int, mod: int = 26) int#
crypton.utils.math.sub_matrices(a: Union[List[List[int]], numpy.ndarray], b: Union[List[List[int]], numpy.ndarray]) numpy.ndarray#

Space#

crypton.utils.space.convert_ints_to_char(array: List[int], space: str) List[str]#

Converts list of integer indices to list of characters

Parameters
  • array (List(int)) – List of integers

  • space (str) – Target space

Returns

List of characters

Return type

List(str)

crypton.utils.space.convert_nested_ints_to_char(array: numpy.ndarray, space: str) List[str]#

Calls the crypton.utils.space.convert_ints_to_char() function repeatedly on every element of the list

Parameters
  • array (np.ndarray) – Nested list of integers

  • space (str) – Target space

Returns

List of strings

Return type

List(str)

crypton.utils.space.get_char_at_index(index: int, space: str) str#

Returns the char at the given index in the given space

Parameters
  • index (int) – Index of the char

  • space (str) – Target space

Returns

Character at the index in the space

Return type

str

crypton.utils.space.get_index_of_char(character: str, space: str) int#

Returns the index of the character in the given space

Parameters
  • character (str) – Character we want to get the index of

  • space (Target space) – str

Returns

Index of the character

Return type

int