






import argparse

import torch

from transformers import NystromformerConfig, NystromformerForMaskedLM
def   lowerCamelCase      (		a_			)			->    Optional[int]:







							if "model" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('model.'				,		''			)
							if "norm1" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('norm1'				,		'attention.output.LayerNorm'			)
							if "norm2" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('norm2'				,		'output.LayerNorm'			)
							if "norm" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('norm'				,		'LayerNorm'			)
							if "transformer" in orig_key:
														lowerCAmelCase_       		=  orig_key.split('.'			)[0].split('_'			)[-1]
														lowerCAmelCase_       		=  orig_key.replace(F'''transformer_{layer_num}'''				,		F'''encoder.layer.{layer_num}'''			)
							if "mha.attn" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('mha.attn'				,		'attention.self'			)
							if "mha" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('mha'				,		'attention'			)
							if "W_q" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('W_q'				,		'self.query'			)
							if "W_k" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('W_k'				,		'self.key'			)
							if "W_v" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('W_v'				,		'self.value'			)
							if "ff1" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('ff1'				,		'intermediate.dense'			)
							if "ff2" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('ff2'				,		'output.dense'			)
							if "ff" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('ff'				,		'output.dense'			)
							if "mlm_class" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('mlm.mlm_class'				,		'cls.predictions.decoder'			)
							if "mlm" in orig_key:
														lowerCAmelCase_       		=  orig_key.replace('mlm'				,		'cls.predictions.transform'			)
							if "cls" not in orig_key:
														lowerCAmelCase_       		=  'nystromformer.' + orig_key

							return orig_key
def   lowerCamelCase      (		a_				,		a_			)			->    int:







							for key in orig_state_dict.copy().keys():
														lowerCAmelCase_       		=  orig_state_dict.pop(a_			)

														if ("pooler" in key) or ("sen_class" in key) or ("conv.bias" in key):
																					continue
														else:
																					lowerCAmelCase_       		=  val

							lowerCAmelCase_       		=  orig_state_dict['cls.predictions.decoder.bias']
							lowerCAmelCase_       		=  (
							    torch.arange(config.max_position_embeddings			).expand((1, -1)			) + 2
							)

							return orig_state_dict
def   lowerCamelCase      (		a_				,		a_				,		a_			)			->    Optional[int]:
							lowerCAmelCase_       		=  torch.load(a_				,		map_location='cpu'			)['model_state_dict']
							lowerCAmelCase_       		=  NystromformerConfig.from_json_file(a_			)
							lowerCAmelCase_       		=  NystromformerForMaskedLM(a_			)

							lowerCAmelCase_       		=  convert_checkpoint_helper(a_				,		a_			)

							model.load_state_dict(a_			)
							model.eval()
							model.save_pretrained(a_			)

							print(F'''Checkpoint successfuly converted. Model saved at {pytorch_dump_path}'''			)


if __name__ == "__main__":
		lowerCamelCase_		  =						argparse.ArgumentParser()
		# Required parameters
		parser.add_argument(
		    """--pytorch_model_path""", default=None, type=str, required=True, help="""Path to Nystromformer pytorch checkpoint."""
		)
		parser.add_argument(
		    """--config_file""",
		    default=None,
		    type=str,
		    required=True,
		    help="""The json file for Nystromformer model config.""",
		)
		parser.add_argument(
		    """--pytorch_dump_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
		)
		lowerCamelCase_		  =						parser.parse_args()
		convert_nystromformer_checkpoint(args.pytorch_model_path, args.config_file, args.pytorch_dump_path)











from __future__ import annotations

from string import ascii_letters
def   lowerCamelCase      (		a_				,		a_				,		a_ = None			)			->    str:
							lowerCAmelCase_       		=  alphabet or ascii_letters

							# The final result string
							lowerCAmelCase_       		=  ''

							for character in input_string:
														if character not in alpha:
																					# Append without encryption if character is not in the alphabet
																					result += character
														else:
																					# Get the index of the new key and make sure it isn't too large
																					lowerCAmelCase_       		=  (alpha.index(a_			) + key) % len(a_			)

																					# Append the encoded character to the alphabet
																					result += alpha[new_key]

							return result
def   lowerCamelCase      (		a_				,		a_				,		a_ = None			)			->    str:
							key *= -1

							return encrypt(a_				,		a_				,		a_			)
def   lowerCamelCase      (		a_				,		a_ = None			)			->    dict[int, str]:
							lowerCAmelCase_       		=  alphabet or ascii_letters

							# To store data on all the combinations
							lowerCAmelCase_       		=  {}

							# Cycle through each combination
							for key in range(1				,		len(a_			) + 1			):
														# Decrypt the message and store the result in the data
														lowerCAmelCase_       		=  decrypt(a_				,		a_				,		a_			)

							return brute_force_data


if __name__ == "__main__":
		while True:
				print(f'''\n{"-" * 1_0}\n Menu\n{"-" * 1_0}''')
				print(*["""1.Encrypt""", """2.Decrypt""", """3.BruteForce""", """4.Quit"""], sep="""\n""")

				# get user input
				lowerCamelCase_		  =						input("""\nWhat would you like to do?: """).strip() or """4"""

				# run functions based on what the user chose
				if choice not in ("1", "2", "3", "4"):
						print("""Invalid choice, please enter a valid choice""")
				elif choice == "1":
						lowerCamelCase_		  =						input("""Please enter the string to be encrypted: """)
						lowerCamelCase_		  =						int(input("""Please enter off-set: """).strip())

						print(encrypt(input_string, key))
				elif choice == "2":
						lowerCamelCase_		  =						input("""Please enter the string to be decrypted: """)
						lowerCamelCase_		  =						int(input("""Please enter off-set: """).strip())

						print(decrypt(input_string, key))
				elif choice == "3":
						lowerCamelCase_		  =						input("""Please enter the string to be decrypted: """)
						lowerCamelCase_		  =						brute_force(input_string)

						for key, value in brute_force_data.items():
								print(f'''Key: {key} | Message: {value}''')

				elif choice == "4":
						print("""Goodbye.""")
						break



