
import os
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
						import torch

						from transformers import GPTaLMHeadModel





@require_torch
@require_sentencepiece
@require_tokenizers
class      UpperCamelCase_			(			unittest.TestCase		):







						'''simple docstring'''



						@slow
						@unittest.skip("Model is not available."    )
						def 					SCREAMING_SNAKE_CASE( self       :Union[str, Any]    )     ->Tuple:
										lowercase						    =			"nvidia/megatron-gpt2-345m/"
										if "MYDIR" in os.environ:
														lowercase						    =			os.path.join(os.environ["MYDIR"]		,						lowerCAmelCase__    )
										lowercase						    =			GPTaLMHeadModel.from_pretrained(lowerCAmelCase__    )
										model.to(lowerCAmelCase__    )
										model.half()

										lowercase						    =			torch.tensor(
										    [[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]]		,						device=lowerCAmelCase__		,						dtype=torch.long		,						)

										with torch.no_grad():
														lowercase						    =			model(lowerCAmelCase__    ).logits

										lowercase						    =			torch.Size((1, 9, 50257)    )
										self.assertEqual(output.shape		,						lowerCAmelCase__    )

										lowercase						    =			torch.tensor(
										    [
										        4.94_14,
										        -0.29_20,
										        -1.21_48,
										        -4.02_73,
										        -0.51_61,
										        -5.21_09,
										        -1.24_12,
										        -1.83_01,
										        -1.77_34,
										        -4.71_48,
										        -0.23_17,
										        -1.08_11,
										        -2.17_77,
										        0.41_41,
										        -3.79_69,
										        -4.05_86,
										        -2.53_32,
										        -3.38_09,
										        4.38_67,
										    ]		,						device=lowerCAmelCase__		,						dtype=torch.half		,						)

										for i in range(19    ):
														lowercase    ,  lowercase						    =			8 * i // 17, 2792 * i  # along the diagonal
														lowercase    ,  lowercase						    =			output[0, r, c], expected_diag[i]
														lowercase						    =			F'''row={r} col={c} computed={computed} expected={expected}'''
														self.assertAlmostEqual(lowerCAmelCase__		,						lowerCAmelCase__		,						delta=1E-4		,						msg=lowerCAmelCase__    )


_snake_case			:       List[Any]      =						{
    "A": ("ABCDEFGHIJKLM", "NOPQRSTUVWXYZ"),
    "B": ("ABCDEFGHIJKLM", "NOPQRSTUVWXYZ"),
    "C": ("ABCDEFGHIJKLM", "ZNOPQRSTUVWXY"),
    "D": ("ABCDEFGHIJKLM", "ZNOPQRSTUVWXY"),
    "E": ("ABCDEFGHIJKLM", "YZNOPQRSTUVWX"),
    "F": ("ABCDEFGHIJKLM", "YZNOPQRSTUVWX"),
    "G": ("ABCDEFGHIJKLM", "XYZNOPQRSTUVW"),
    "H": ("ABCDEFGHIJKLM", "XYZNOPQRSTUVW"),
    "I": ("ABCDEFGHIJKLM", "WXYZNOPQRSTUV"),
    "J": ("ABCDEFGHIJKLM", "WXYZNOPQRSTUV"),
    "K": ("ABCDEFGHIJKLM", "VWXYZNOPQRSTU"),
    "L": ("ABCDEFGHIJKLM", "VWXYZNOPQRSTU"),
    "M": ("ABCDEFGHIJKLM", "UVWXYZNOPQRST"),
    "N": ("ABCDEFGHIJKLM", "UVWXYZNOPQRST"),
    "O": ("ABCDEFGHIJKLM", "TUVWXYZNOPQRS"),
    "P": ("ABCDEFGHIJKLM", "TUVWXYZNOPQRS"),
    "Q": ("ABCDEFGHIJKLM", "STUVWXYZNOPQR"),
    "R": ("ABCDEFGHIJKLM", "STUVWXYZNOPQR"),
    "S": ("ABCDEFGHIJKLM", "RSTUVWXYZNOPQ"),
    "T": ("ABCDEFGHIJKLM", "RSTUVWXYZNOPQ"),
    "U": ("ABCDEFGHIJKLM", "QRSTUVWXYZNOP"),
    "V": ("ABCDEFGHIJKLM", "QRSTUVWXYZNOP"),
    "W": ("ABCDEFGHIJKLM", "PQRSTUVWXYZNO"),
    "X": ("ABCDEFGHIJKLM", "PQRSTUVWXYZNO"),
    "Y": ("ABCDEFGHIJKLM", "OPQRSTUVWXYZN"),
    "Z": ("ABCDEFGHIJKLM", "OPQRSTUVWXYZN"),
}

def    __snake_case       (  __magic_name__	):







				'''simple docstring'''


				return [alphabet[char] for char in key.upper()]

def    __snake_case       (  __magic_name__		,						__magic_name__	):







				'''simple docstring'''


				lowercase						    =			""
				lowercase						    =			0
				lowercase						    =			generate_table(__magic_name__	)
				for char in words.upper():
								cipher += get_opponent(table[count]		,						__magic_name__	)
								lowercase						    =			(count + 1) % len(__magic_name__	)
				return cipher

def    __snake_case       (  __magic_name__		,						__magic_name__	):







				'''simple docstring'''


				return encrypt(__magic_name__		,						__magic_name__	)

def    __snake_case       (  __magic_name__		,						__magic_name__	):







				'''simple docstring'''


				lowercase						    =			0 if char in table[0] else 1
				lowercase						    =			table[row].index(__magic_name__	)
				return row, col

def    __snake_case       (  __magic_name__		,						__magic_name__	):







				'''simple docstring'''


				lowercase    ,  lowercase						    =			get_position(__magic_name__		,						char.upper()	)
				if row == 1:
								return table[0][col]
				else:
								return table[1][col] if row == 0 else char


if __name__ == "__main__":
						import doctest

						doctest.testmod()  # Fist ensure that all our tests are passing...
						_snake_case			:       List[Any]      =						input("Enter key: ").strip()
						_snake_case			:       Optional[int]      =						input("Enter text to encrypt: ").strip()
						_snake_case			:       Optional[Any]      =						encrypt(key, text)

						print(F"Encrypted: {cipher_text}")
						print(F"Decrypted with key: {decrypt(key, cipher_text)}")
