





"""simple docstring"""




from __future__ import annotations





def 		UpperCAmelCase__						(	_UpperCAmelCase					,   _UpperCAmelCase   ):






  """simple docstring"""





  A_		,			A_		,			A_    :			Dict									=    '', '', ''
  A_    :			Any									=    []

  for character in message_part:
    tmp.append(character_to_number[character]   )

  for each in tmp:
    one += each[0]
    two += each[1]
    three += each[2]

  return one + two + three





def 		UpperCAmelCase__						(	_UpperCAmelCase					,   _UpperCAmelCase   ):






  """simple docstring"""





  A_		,			A_    :			List[str]									=    '', ''
  A_    :			str									=    []

  for character in message_part:
    this_part += character_to_number[character]

  for digit in this_part:
    tmp += digit
    if len(_UpperCAmelCase   ) == len(_UpperCAmelCase   ):
      result.append(_UpperCAmelCase   )
      A_    :			Union[str, Any]									=    ''

  return result[0], result[1], result[2]





def 		UpperCAmelCase__						(	_UpperCAmelCase					,   _UpperCAmelCase   ):






  """simple docstring"""





  A_    :			Tuple									=    alphabet.replace(' '					,   ''   ).upper()
  A_    :			Tuple									=    message.replace(' '					,   ''   ).upper()

  # Check length and characters
  if len(_UpperCAmelCase   ) != 27:
    raise KeyError('Length of alphabet has to be 27.'   )
  for each in message:
    if each not in alphabet:
      raise ValueError('Each message character has to be included in alphabet!'   )

    # Generate dictionares
  A_    :			int									=    (
      '111',
      '112',
      '113',
      '121',
      '122',
      '123',
      '131',
      '132',
      '133',
      '211',
      '212',
      '213',
      '221',
      '222',
      '223',
      '231',
      '232',
      '233',
      '311',
      '312',
      '313',
      '321',
      '322',
      '323',
      '331',
      '332',
      '333',
  )
  A_    :			int									=    {}
  A_    :			List[str]									=    {}
  for letter, number in zip(_UpperCAmelCase					,   _UpperCAmelCase   ):
    A_    :			Dict									=    number
    A_    :			str									=    letter

  return message, alphabet, character_to_number, number_to_character





def 		UpperCAmelCase__						(	_UpperCAmelCase					,   _UpperCAmelCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."					,   _UpperCAmelCase = 5   ):






  """simple docstring"""





  A_		,			A_		,			A_		,			A_    :			Dict									=    __prepare(
      _UpperCAmelCase					,   _UpperCAmelCase   )
  A_		,			A_    :			List[str]									=    '', ''

  for i in range(0					,   len(_UpperCAmelCase   ) + 1					,   _UpperCAmelCase   ):
    encrypted_numeric += __encrypt_part(
        message[i : i + period]					,   _UpperCAmelCase   )

  for i in range(0					,   len(_UpperCAmelCase   )					,   3   ):
    encrypted += number_to_character[encrypted_numeric[i : i + 3]]

  return encrypted





def 		UpperCAmelCase__						(	_UpperCAmelCase					,   _UpperCAmelCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."					,   _UpperCAmelCase = 5   ):






  """simple docstring"""





  A_		,			A_		,			A_		,			A_    :			List[str]									=    __prepare(
      _UpperCAmelCase					,   _UpperCAmelCase   )
  A_    :			List[str]									=    []
  A_    :			int									=    ''

  for i in range(0					,   len(_UpperCAmelCase   ) + 1					,   _UpperCAmelCase   ):
    A_		,			A_		,			A_    :			Tuple									=    __decrypt_part(message[i : i + period]					,   _UpperCAmelCase   )

    for j in range(0					,   len(_UpperCAmelCase   )   ):
      decrypted_numeric.append(a[j] + b[j] + c[j]   )

  for each in decrypted_numeric:
    decrypted += number_to_character[each]

  return decrypted


if __name__ == "__main__":
   lowerCamelCase_	:		Union[str, Any]         =   'DEFEND THE EAST WALL OF THE CASTLE.'
   lowerCamelCase_	:		Optional[int]         =   encrypt_message(msg, 'EPSDUCVWYM.ZLKXNBTFGORIJHAQ')
   lowerCamelCase_	:		Tuple         =   decrypt_message(encrypted, 'EPSDUCVWYM.ZLKXNBTFGORIJHAQ')
   print(F"Encrypted: {encrypted}\nDecrypted: {decrypted}")






"""simple docstring"""




import hashlib
import importlib.util
import json
import os
import pathlib
from types import ModuleType

import pytest
import requests

lowerCamelCase_	:		int         =   pathlib.Path.cwd().joinpath('project_euler')
lowerCamelCase_	:		str         =   pathlib.Path.cwd().joinpath(
    'scripts', 'project_euler_answers.json'
)

with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
   lowerCamelCase_	:		dict[str, str]         =   json.load(file_handle)





def 		UpperCAmelCase__						(	_UpperCAmelCase   ):






  """simple docstring"""





  A_    :			List[str]									=    importlib.util.spec_from_file_location(file_path.name					,   str(_UpperCAmelCase   )   )
  A_    :			int									=    importlib.util.module_from_spec(_UpperCAmelCase   )  # type: ignore
  spec.loader.exec_module(_UpperCAmelCase   )  # type: ignore
  return module





def 		UpperCAmelCase__						(	):






  """simple docstring"""





  A_    :			Tuple									=    []
  for problem_dir_path in PROJECT_EULER_DIR_PATH.iterdir():
    if problem_dir_path.is_file() or problem_dir_path.name.startswith('_'   ):
      continue
    for file_path in problem_dir_path.iterdir():
      if file_path.suffix != ".py" or file_path.name.startswith(('_', 'test')   ):
        continue
      solution_file_paths.append(_UpperCAmelCase   )
  return solution_file_paths





def 		UpperCAmelCase__						(	):






  """simple docstring"""





  with open(os.environ['GITHUB_EVENT_PATH']   ) as file:
    A_    :			str									=    json.load(_UpperCAmelCase   )
  return event["pull_request"]["url"] + "/files"





def 		UpperCAmelCase__						(	):






  """simple docstring"""





  A_    :			Any									=    []
  A_    :			Optional[Any]									=    {
      'Accept': 'application/vnd.github.v3+json',
      'Authorization': 'token ' + os.environ['GITHUB_TOKEN'],
  }
  A_    :			Union[str, Any]									=    requests.get(get_files_url()					,   headers=_UpperCAmelCase   ).json()
  for file in files:
    A_    :			Optional[int]									=    pathlib.Path.cwd().joinpath(file['filename']   )
    if (
        filepath.suffix != ".py"
        or filepath.name.startswith(('_', 'test')   )
        or not filepath.name.startswith('sol'   )
    ):
      continue
    solution_file_paths.append(_UpperCAmelCase   )
  return solution_file_paths





def 		UpperCAmelCase__						(	):






  """simple docstring"""





  if os.environ.get('CI'   ) and os.environ.get('GITHUB_EVENT_NAME'   ) == "pull_request":
    # Return only if there are any, otherwise default to all solutions
    if filepaths := added_solution_file_path():
      return filepaths
  return all_solution_file_paths()





@pytest.mark.parametrize(
    'solution_path'					,   collect_solution_file_paths()					,   ids=lambda _UpperCAmelCase   : f"""{path.parent.name}/{path.name}"""					,   )
def 		UpperCAmelCase__						(	_UpperCAmelCase   ):






  """simple docstring"""





  A_    :			str									=    solution_path.parent.name[8:].zfill(3   )
  A_    :			str									=    PROBLEM_ANSWERS[problem_number]
  A_    :			List[Any]									=    convert_path_to_module(_UpperCAmelCase   )
  A_    :			Optional[int]									=    str(solution_module.solution()   )  # type: ignore
  A_    :			Any									=    hashlib.shaaaa(answer.encode()   ).hexdigest()
  assert (
      answer == expected
  ), f"""Expected solution to {problem_number} to have hash {expected}, got {answer}"""