


import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

__lowerCAmelCase      :					int    							=3


def 			_UpperCamelCase				( lowercase__ ):
						print('''Generating primitive root of p''' )
						while True:
												__SCREAMING_SNAKE_CASE		:	Optional[int]						     =						random.randrange(3       ,			_lowerCAmelCase )
												if pow(_lowerCAmelCase       ,			2       ,			_lowerCAmelCase ) == 1:
																		continue
												if pow(_lowerCAmelCase       ,			_lowerCAmelCase       ,			_lowerCAmelCase ) == 1:
																		continue
												return g


def 			_UpperCamelCase				( lowercase__ ):
						print('''Generating prime p...''' )
						__SCREAMING_SNAKE_CASE		:	Tuple						     =						rabin_miller.generate_large_prime(_lowerCAmelCase )  # select large prime number.
						__SCREAMING_SNAKE_CASE		:	Union[str, Any]						     =						primitive_root(_lowerCAmelCase )  # one primitive root on modulo p.
						__SCREAMING_SNAKE_CASE		:	Dict						     =						random.randrange(3       ,			_lowerCAmelCase )  # private_key -> have to be greater than 2 for safety.
						__SCREAMING_SNAKE_CASE		:	List[Any]						     =						cryptomath.find_mod_inverse(pow(_lowerCAmelCase       ,			_lowerCAmelCase       ,			_lowerCAmelCase )       ,			_lowerCAmelCase )

						__SCREAMING_SNAKE_CASE		:	Optional[Any]						     =						(key_size, e_a, e_a, p)
						__SCREAMING_SNAKE_CASE		:	Union[str, Any]						     =						(key_size, d)

						return public_key, private_key


def 			_UpperCamelCase				( lowercase__       ,			lowercase__ ):
						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()

						__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Optional[int]						     =						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 			_UpperCamelCase				( ):
						print('''Making key files...''' )
						make_key_files('''elgamal'''       ,			2048 )
						print('''Key files generation successful''' )


if __name__ == "__main__":
						main()


"""simple docstring"""
import os

def  lowercase     ():
						with open(os.path.dirname(_lowerCAmelCase						) + """/grid.txt"""						) as f:
												__lowerCAmelCase     =  []  # noqa: E741
												for _ in range(20						):
																		l.append([int(_lowerCAmelCase						) for x in f.readline().split()]						)

												__lowerCAmelCase     =  0

												# right
												for i in range(20						):
																		for j in range(17						):
																								__lowerCAmelCase     =  l[i][j] * l[i][j + 1] * l[i][j + 2] * l[i][j + 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # down
												for i in range(17						):
																		for j in range(20						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j] * l[i + 2][j] * l[i + 3][j]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # diagonal 1
												for i in range(17						):
																		for j in range(17						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j + 1] * l[i + 2][j + 2] * l[i + 3][j + 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # diagonal 2
												for i in range(17						):
																		for j in range(3 ,    20						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j - 1] * l[i + 2][j - 2] * l[i + 3][j - 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp
												return maximum


if __name__ == "__main__":
			print(solution())
