

from __future__ import annotations

import math






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__     ,			lowerCamelCase__      )  ->					Tuple:
	if len(lowerCamelCase__      ) != 2 or len(a[0]      ) != 2 or len(lowerCamelCase__      ) != 2 or len(b[0]      ) != 2:
		raise Exception('Matrices are not 2x2'      )
	__lowerCamelCase    :    List[str] 	=			[
	    [a[0][0] * b[0][0] + a[0][1] * b[1][0], a[0][0] * b[0][1] + a[0][1] * b[1][1]],
	    [a[1][0] * b[0][0] + a[1][1] * b[1][0], a[1][0] * b[0][1] + a[1][1] * b[1][1]],
	]
	return new_matrix






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__     ,			lowerCamelCase__      )  ->					List[str]:
	return [
	    [matrix_a[row][col] + matrix_b[row][col] for col in range(len(matrix_a[row]      )      )]
	    for row in range(len(lowerCamelCase__      )      )
	]






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__     ,			lowerCamelCase__      )  ->					Tuple:
	return [
	    [matrix_a[row][col] - matrix_b[row][col] for col in range(len(matrix_a[row]      )      )]
	    for row in range(len(lowerCamelCase__      )      )
	]






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__      )  ->					Any:
	if len(lowerCamelCase__      ) % 2 != 0 or len(a[0]      ) % 2 != 0:
		raise Exception('Odd matrices are not supported!'      )

	__lowerCamelCase    :    str 	=			len(lowerCamelCase__      )
	__lowerCamelCase    :    Union[str, Any] 	=			matrix_length // 2

	__lowerCamelCase    :    List[Any] 	=			[[a[i][j] for j in range(lowerCamelCase__     ,			lowerCamelCase__      )] for i in range(lowerCamelCase__      )]
	__lowerCamelCase    :    Union[str, Any] 	=			[
	    [a[i][j] for j in range(lowerCamelCase__     ,			lowerCamelCase__      )] for i in range(lowerCamelCase__     ,			lowerCamelCase__      )
	]

	__lowerCamelCase    :    Optional[int] 	=			[[a[i][j] for j in range(lowerCamelCase__      )] for i in range(lowerCamelCase__      )]
	__lowerCamelCase    :    List[Any] 	=			[[a[i][j] for j in range(lowerCamelCase__      )] for i in range(lowerCamelCase__     ,			lowerCamelCase__      )]

	return top_left, top_right, bot_left, bot_right






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__      )  ->					List[str]:
	return len(lowerCamelCase__      ), len(matrix[0]      )






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__      )  ->					Optional[int]:
	print('\n'.join(str(lowerCamelCase__      ) for line in matrix      )      )






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__     ,			lowerCamelCase__      )  ->					Any:
	if matrix_dimensions(lowerCamelCase__      ) == (2, 2):
		return default_matrix_multiplication(lowerCamelCase__     ,			lowerCamelCase__      )

	__lowerCamelCase	,			__lowerCamelCase	,			__lowerCamelCase	,			__lowerCamelCase    :    List[Any] 	=			split_matrix(lowerCamelCase__      )
	__lowerCamelCase	,			__lowerCamelCase	,			__lowerCamelCase	,			__lowerCamelCase    :    Dict 	=			split_matrix(lowerCamelCase__      )

	__lowerCamelCase    :    Union[str, Any] 	=			actual_strassen(lowerCamelCase__     ,			matrix_subtraction(lowerCamelCase__     ,			lowerCamelCase__      )      )
	__lowerCamelCase    :    Tuple 	=			actual_strassen(matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )     ,			lowerCamelCase__      )
	__lowerCamelCase    :    Any 	=			actual_strassen(matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )     ,			lowerCamelCase__      )
	__lowerCamelCase    :    List[str] 	=			actual_strassen(lowerCamelCase__     ,			matrix_subtraction(lowerCamelCase__     ,			lowerCamelCase__      )      )
	__lowerCamelCase    :    Union[str, Any] 	=			actual_strassen(matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )     ,			matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )      )
	__lowerCamelCase    :    Optional[Any] 	=			actual_strassen(matrix_subtraction(lowerCamelCase__     ,			lowerCamelCase__      )     ,			matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )      )
	__lowerCamelCase    :    Dict 	=			actual_strassen(matrix_subtraction(lowerCamelCase__     ,			lowerCamelCase__      )     ,			matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )      )

	__lowerCamelCase    :    int 	=			matrix_addition(matrix_subtraction(matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )     ,			lowerCamelCase__      )     ,			lowerCamelCase__      )
	__lowerCamelCase    :    Optional[Any] 	=			matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )
	__lowerCamelCase    :    Dict 	=			matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )
	__lowerCamelCase    :    int 	=			matrix_subtraction(matrix_subtraction(matrix_addition(lowerCamelCase__     ,			lowerCamelCase__      )     ,			lowerCamelCase__      )     ,			lowerCamelCase__      )

	# construct the new matrix from our 4 quadrants
	__lowerCamelCase    :    Dict 	=			[]
	for i in range(len(lowerCamelCase__      )      ):
		new_matrix.append(top_left[i] + top_right[i]      )
	for i in range(len(lowerCamelCase__      )      ):
		new_matrix.append(bot_left[i] + bot_right[i]      )
	return new_matrix






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__     ,			lowerCamelCase__      )  ->					Tuple:
	if matrix_dimensions(lowerCamelCase__      )[1] != matrix_dimensions(lowerCamelCase__      )[0]:
		__lowerCamelCase    :    Union[str, Any] 	=			(
		    'Unable to multiply these matrices, please check the dimensions.\n'
		    F"Matrix A: {matrixa}\n"
		    F"Matrix B: {matrixa}"
		)
		raise Exception(lowerCamelCase__      )
	__lowerCamelCase    :    List[Any] 	=			matrix_dimensions(lowerCamelCase__      )
	__lowerCamelCase    :    Dict 	=			matrix_dimensions(lowerCamelCase__      )

	if dimensiona[0] == dimensiona[1] and dimensiona[0] == dimensiona[1]:
		return [matrixa, matrixa]

	__lowerCamelCase    :    Any 	=			max(*lowerCamelCase__     ,			*lowerCamelCase__      )
	__lowerCamelCase    :    Tuple 	=			int(math.pow(2     ,			math.ceil(math.loga(lowerCamelCase__      )      )      )      )
	__lowerCamelCase    :    Union[str, Any] 	=			matrixa
	__lowerCamelCase    :    Any 	=			matrixa

	# Adding zeros to the matrices so that the arrays dimensions are the same and also
	# power of 2
	for i in range(0     ,			lowerCamelCase__      ):
		if i < dimensiona[0]:
			for _ in range(dimensiona[1]     ,			lowerCamelCase__      ):
				new_matrixa[i].append(0      )
		else:
			new_matrixa.append([0] * maxim      )
		if i < dimensiona[0]:
			for _ in range(dimensiona[1]     ,			lowerCamelCase__      ):
				new_matrixa[i].append(0      )
		else:
			new_matrixa.append([0] * maxim      )

	__lowerCamelCase    :    Any 	=			actual_strassen(lowerCamelCase__     ,			lowerCamelCase__      )

	# Removing the additional zeros
	for i in range(0     ,			lowerCamelCase__      ):
		if i < dimensiona[0]:
			for _ in range(dimensiona[1]     ,			lowerCamelCase__      ):
				final_matrix[i].pop()
		else:
			final_matrix.pop()
	return final_matrix


if __name__ == "__main__":
					a		=[
					    [2, 3, 4, 5],
					    [6, 4, 3, 1],
					    [2, 3, 6, 7],
					    [3, 1, 2, 4],
					    [2, 3, 4, 5],
					    [6, 4, 3, 1],
					    [2, 3, 6, 7],
					    [3, 1, 2, 4],
					    [2, 3, 4, 5],
					    [6, 2, 3, 1],
					]
					a		=[[0, 2, 1, 1], [16, 2, 3, 3], [2, 2, 7, 7], [13, 11, 22, 4]]
					print(strassen(matrixa, matrixa))







import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

a		=3






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__      )  ->					int:
	print('Generating primitive root of p'      )
	while True:
		__lowerCamelCase    :    Tuple 	=			random.randrange(3     ,			lowerCamelCase__      )
		if pow(lowerCamelCase__     ,			2     ,			lowerCamelCase__      ) == 1:
			continue
		if pow(lowerCamelCase__     ,			lowerCamelCase__     ,			lowerCamelCase__      ) == 1:
			continue
		return g






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__      )  ->					tuple[tuple[int, int, int, int], tuple[int, int]]:
	print('Generating prime p...'      )
	__lowerCamelCase    :    List[str] 	=			rabin_miller.generate_large_prime(lowerCamelCase__      )  # select large prime number.
	__lowerCamelCase    :    Dict 	=			primitive_root(lowerCamelCase__      )  # one primitive root on modulo p.
	__lowerCamelCase    :    Optional[int] 	=			random.randrange(3     ,			lowerCamelCase__      )  # private_key -> have to be greater than 2 for safety.
	__lowerCamelCase    :    List[Any] 	=			cryptomath.find_mod_inverse(pow(lowerCamelCase__     ,			lowerCamelCase__     ,			lowerCamelCase__      )     ,			lowerCamelCase__      )

	__lowerCamelCase    :    int 	=			(key_size, e_a, e_a, p)
	__lowerCamelCase    :    str 	=			(key_size, d)

	return public_key, private_key






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__     ,			lowerCamelCase__      )  ->					None:
	if os.path.exists(F"{name}_pubkey.txt"      ) or os.path.exists(F"{name}_privkey.txt"      ):
		print('\nWARNING:'      )
		print(
		    F"\"{name}_pubkey.txt\" or \"{name}_privkey.txt\" already exists. \n"
		    'Use a different name or delete these files and re-run this program.'      )
		sys.exit()

	__lowerCamelCase	,			__lowerCamelCase    :    List[Any] 	=			generate_key(lowerCamelCase__      )
	print(F"\nWriting public key to file {name}_pubkey.txt..."      )
	with open(F"{name}_pubkey.txt"     ,			'w'      ) as fo:
		fo.write(F"{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}"      )

	print(F"Writing private key to file {name}_privkey.txt..."      )
	with open(F"{name}_privkey.txt"     ,			'w'      ) as fo:
		fo.write(F"{private_key[0]},{private_key[1]}"      )






def        SCREAMING_SNAKE_CASE__	(  )  ->					None:
	print('Making key files...'      )
	make_key_files('elgamal'     ,			2_0_4_8      )
	print('Key files generation successful'      )


if __name__ == "__main__":
					main()




