
import unittest

from transformers import BertGenerationConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import BertGenerationDecoder, BertGenerationEncoder

class       a		:







							def __init__(						self  :  Any      ,				snake_case__  :  int      ,				snake_case__  :  Union[str, Any]=13      ,				snake_case__  :  Any=7      ,				snake_case__  :  Tuple=True      ,				snake_case__  :  Dict=True      ,				snake_case__  :  str=99      ,				snake_case__  :  List[str]=32      ,				snake_case__  :  int=5      ,				snake_case__  :  int=4      ,				snake_case__  :  Optional[int]=37      ,				snake_case__  :  str="gelu"      ,				snake_case__  :  int=0.1      ,				snake_case__  :  int=0.1      ,				snake_case__  :  str=50      ,				snake_case__  :  Optional[int]=0.0_2      ,				snake_case__  :  Dict=True      ,				snake_case__  :  Optional[int]=None      ,				):
								"""simple docstring"""







								__lowerCAmelCase         =							parent
								__lowerCAmelCase         =							batch_size
								__lowerCAmelCase         =							seq_length
								__lowerCAmelCase         =							is_training
								__lowerCAmelCase         =							use_input_mask
								__lowerCAmelCase         =							vocab_size
								__lowerCAmelCase         =							hidden_size
								__lowerCAmelCase         =							num_hidden_layers
								__lowerCAmelCase         =							num_attention_heads
								__lowerCAmelCase         =							intermediate_size
								__lowerCAmelCase         =							hidden_act
								__lowerCAmelCase         =							hidden_dropout_prob
								__lowerCAmelCase         =							attention_probs_dropout_prob
								__lowerCAmelCase         =							max_position_embeddings
								__lowerCAmelCase         =							initializer_range
								__lowerCAmelCase         =							use_labels
								__lowerCAmelCase         =							scope







							def       UpperCAmelCase__					(						self  :  List[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							ids_tensor([self.batch_size, self.seq_length]      ,				self.vocab_size )

								__lowerCAmelCase         =							None
								if self.use_input_mask:
									__lowerCAmelCase         =							random_attention_mask([self.batch_size, self.seq_length] )

								if self.use_labels:
									__lowerCAmelCase         =							ids_tensor([self.batch_size, self.seq_length]      ,				self.vocab_size )

								__lowerCAmelCase         =							self.get_config()

								return config, input_ids, input_mask, token_labels







							def       UpperCAmelCase__					(						self  :  List[Any] ):
								"""simple docstring"""







								return BertGenerationConfig(
								    vocab_size=self.vocab_size      ,				hidden_size=self.hidden_size      ,				num_hidden_layers=self.num_hidden_layers      ,				num_attention_heads=self.num_attention_heads      ,				intermediate_size=self.intermediate_size      ,				hidden_act=self.hidden_act      ,				hidden_dropout_prob=self.hidden_dropout_prob      ,				attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,				max_position_embeddings=self.max_position_embeddings      ,				is_decoder=snake_case__      ,				initializer_range=self.initializer_range      ,				)







							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								(
								    (
								    __lowerCAmelCase						
								)   ,						(
								    __lowerCAmelCase						
								)   ,						(
								    __lowerCAmelCase						
								)   ,						(
								    __lowerCAmelCase						
								)   ,												
								)         =							self.prepare_config_and_inputs()

								__lowerCAmelCase         =							True
								__lowerCAmelCase         =							floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
								__lowerCAmelCase         =							ids_tensor([self.batch_size, self.seq_length]      ,				vocab_size=2 )

								return (
								    config,
								    input_ids,
								    input_mask,
								    token_labels,
								    encoder_hidden_states,
								    encoder_attention_mask,
								)







							def       UpperCAmelCase__					(						self  :  Dict      ,				snake_case__  :  Optional[Any]      ,				snake_case__  :  int      ,				snake_case__  :  Dict      ,				snake_case__  :  str      ,				**snake_case__  :  List[str]      ,				):
								"""simple docstring"""







								__lowerCAmelCase         =							BertGenerationEncoder(config=snake_case__ )
								model.to(snake_case__ )
								model.eval()
								__lowerCAmelCase         =							model(snake_case__      ,				attention_mask=snake_case__ )
								__lowerCAmelCase         =							model(snake_case__ )
								self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.hidden_size) )







							def       UpperCAmelCase__					(						self  :  Optional[int]      ,				snake_case__  :  str      ,				snake_case__  :  List[str]      ,				snake_case__  :  List[Any]      ,				snake_case__  :  Union[str, Any]      ,				snake_case__  :  List[str]      ,				snake_case__  :  Optional[int]      ,				**snake_case__  :  Union[str, Any]      ,				):
								"""simple docstring"""







								__lowerCAmelCase         =							True
								__lowerCAmelCase         =							BertGenerationEncoder(config=snake_case__ )
								model.to(snake_case__ )
								model.eval()
								__lowerCAmelCase         =							model(
								    snake_case__      ,				attention_mask=snake_case__      ,				encoder_hidden_states=snake_case__      ,				encoder_attention_mask=snake_case__      ,				)
								__lowerCAmelCase         =							model(
								    snake_case__      ,				attention_mask=snake_case__      ,				encoder_hidden_states=snake_case__      ,				)
								self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.hidden_size) )







							def       UpperCAmelCase__					(						self  :  int      ,				snake_case__  :  Any      ,				snake_case__  :  List[Any]      ,				snake_case__  :  Optional[int]      ,				snake_case__  :  Tuple      ,				snake_case__  :  List[str]      ,				snake_case__  :  str      ,				**snake_case__  :  int      ,				):
								"""simple docstring"""







								__lowerCAmelCase         =							True
								__lowerCAmelCase         =							True
								__lowerCAmelCase         =							BertGenerationDecoder(config=snake_case__ ).to(snake_case__ ).eval()

								# first forward pass
								__lowerCAmelCase         =							model(
								    snake_case__      ,				attention_mask=snake_case__      ,				encoder_hidden_states=snake_case__      ,				encoder_attention_mask=snake_case__      ,				use_cache=snake_case__      ,				)
								__lowerCAmelCase         =							outputs.past_key_values

								# create hypothetical multiple next token and extent to next_input_ids
								__lowerCAmelCase         =							ids_tensor((self.batch_size, 3)      ,				config.vocab_size )
								__lowerCAmelCase         =							ids_tensor((self.batch_size, 3)      ,				vocab_size=2 )

								# append to next input_ids and
								__lowerCAmelCase         =							torch.cat([input_ids, next_tokens]      ,				dim=-1 )
								__lowerCAmelCase         =							torch.cat([input_mask, next_mask]      ,				dim=-1 )

								__lowerCAmelCase         =							model(
								    snake_case__      ,				attention_mask=snake_case__      ,				encoder_hidden_states=snake_case__      ,				encoder_attention_mask=snake_case__      ,				output_hidden_states=snake_case__      ,				)["hidden_states"][0]
								__lowerCAmelCase         =							model(
								    snake_case__      ,				attention_mask=snake_case__      ,				encoder_hidden_states=snake_case__      ,				encoder_attention_mask=snake_case__      ,				past_key_values=snake_case__      ,				output_hidden_states=snake_case__      ,				)["hidden_states"][0]

								# select random slice
								__lowerCAmelCase         =							ids_tensor((1,)      ,				output_from_past.shape[-1] ).item()
								__lowerCAmelCase         =							output_from_no_past[:, -3:, random_slice_idx].detach()
								__lowerCAmelCase         =							output_from_past[:, :, random_slice_idx].detach()

								self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1] )

								# test that outputs are equal for slice
								self.parent.assertTrue(torch.allclose(snake_case__      ,				snake_case__      ,				atol=1E-3 ) )







							def       UpperCAmelCase__					(						self  :  Optional[int]      ,				snake_case__  :  Any      ,				snake_case__  :  List[str]      ,				snake_case__  :  Dict      ,				snake_case__  :  List[Any]      ,				*snake_case__  :  int      ,				):
								"""simple docstring"""







								__lowerCAmelCase         =							BertGenerationDecoder(snake_case__ )
								model.to(snake_case__ )
								model.eval()
								__lowerCAmelCase         =							model(snake_case__      ,				attention_mask=snake_case__      ,				labels=snake_case__ )
								self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.vocab_size) )







							def       UpperCAmelCase__					(						self  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							self.prepare_config_and_inputs()
								__lowerCAmelCase         =							{"input_ids": input_ids, "attention_mask": input_mask}
								return config, inputs_dict

@require_torch
class       a		(   __UpperCAmelCase      ,	__UpperCAmelCase      ,	__UpperCAmelCase      ,	unittest.TestCase					):
							lowercase_		:						Optional[Any]   							=  (BertGenerationEncoder, BertGenerationDecoder) if is_torch_available() else ()
							lowercase_		:						Tuple   							=  (BertGenerationDecoder,) if is_torch_available() else ()
							lowercase_		:						List[Any]   							=  (
							    {'feature-extraction': BertGenerationEncoder, 'text-generation': BertGenerationDecoder}
							    if is_torch_available()
							    else {}
							)







							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								__lowerCAmelCase         =							BertGenerationEncoderTester(self )
								__lowerCAmelCase         =							ConfigTester(self      ,				config_class=snake_case__      ,				hidden_size=37 )







							def       UpperCAmelCase__					(						self  :  List[Any] ):
								"""simple docstring"""







								self.config_tester.run_common_tests()







							def       UpperCAmelCase__					(						self  :  Optional[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*snake_case__ )







							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs()
								__lowerCAmelCase         =							"bert"
								self.model_tester.create_and_check_model(snake_case__      ,				snake_case__      ,				snake_case__      ,				snake_case__ )







							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs_for_decoder()
								self.model_tester.create_and_check_model_as_decoder(*snake_case__ )







							def       UpperCAmelCase__					(						self  :  Optional[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs_for_decoder()
								self.model_tester.create_and_check_decoder_model_past_large_inputs(*snake_case__ )







							def       UpperCAmelCase__					(						self  :  List[Any] ):
								"""simple docstring"""







								(
								    (
								    __lowerCAmelCase						
								)   ,						(
								    __lowerCAmelCase						
								)   ,						(
								    __lowerCAmelCase						
								)   ,						(
								    __lowerCAmelCase						
								)   ,						(
								    __lowerCAmelCase						
								)   ,						(
								    __lowerCAmelCase						
								)   ,												
								)         =							self.model_tester.prepare_config_and_inputs_for_decoder()

								__lowerCAmelCase         =							None

								self.model_tester.create_and_check_model_as_decoder(
								    snake_case__      ,				snake_case__      ,				snake_case__      ,				snake_case__      ,				snake_case__      ,				snake_case__      ,				)







							def       UpperCAmelCase__					(						self  :  Union[str, Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model_tester.prepare_config_and_inputs_for_decoder()
								self.model_tester.create_and_check_for_causal_lm(*snake_case__ )







							@slow
							def       UpperCAmelCase__					(						self  :  List[str] ):
								"""simple docstring"""







								__lowerCAmelCase         =							BertGenerationEncoder.from_pretrained("google/bert_for_seq_generation_L-24_bbc_encoder" )
								self.assertIsNotNone(snake_case__ )

@require_torch
class       a		(   unittest.TestCase					):







							@slow
							def       UpperCAmelCase__					(						self  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase         =							BertGenerationEncoder.from_pretrained("google/bert_for_seq_generation_L-24_bbc_encoder" )
								__lowerCAmelCase         =							torch.tensor([[101, 7_592, 1_010, 2_026, 3_899, 2_003, 10_140, 102]] )
								with torch.no_grad():
									__lowerCAmelCase         =							model(snake_case__ )[0]
								__lowerCAmelCase         =							torch.Size([1, 8, 1_024] )
								self.assertEqual(output.shape      ,				snake_case__ )
								__lowerCAmelCase         =							torch.tensor(
								    [[[0.1_7_7_5, 0.0_0_8_3, -0.0_3_2_1], [1.6_0_0_2, 0.1_2_8_7, 0.3_9_1_2], [2.1_4_7_3, 0.5_7_9_1, 0.6_0_6_6]]] )
								self.assertTrue(torch.allclose(output[:, :3, :3]      ,				snake_case__      ,				atol=1E-4 ) )

@require_torch
class       a		(   unittest.TestCase					):







							@slow
							def       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							BertGenerationDecoder.from_pretrained("google/bert_for_seq_generation_L-24_bbc_encoder" )
								__lowerCAmelCase         =							torch.tensor([[101, 7_592, 1_010, 2_026, 3_899, 2_003, 10_140, 102]] )
								with torch.no_grad():
									__lowerCAmelCase         =							model(snake_case__ )[0]
								__lowerCAmelCase         =							torch.Size([1, 8, 50_358] )
								self.assertEqual(output.shape      ,				snake_case__ )
								__lowerCAmelCase         =							torch.tensor(
								    [[[-0.5_7_8_8, -2.5_9_9_4, -3.7_0_5_4], [0.0_4_3_8, 4.7_9_9_7, 1.8_7_9_5], [1.5_8_6_2, 6.6_4_0_9, 4.4_6_3_8]]] )
								self.assertTrue(torch.allclose(output[:, :3, :3]      ,				snake_case__      ,				atol=1E-4 ) )








from binascii import hexlify
from hashlib import shaaaa
from os import urandom

# RFC 3526 - More Modular Exponential (MODP) Diffie-Hellman groups for
# Internet Key Exchange (IKE) https://tools.ietf.org/html/rfc3526

UpperCamelCase_   	=	{
    # 1536-bit
    5: {
        "prime": int(
            "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
            + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
            + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
            + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
            + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
            + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
            + "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
            + "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF",
            base=1_6,
        ),
        "generator": 2,
    },
    # 2048-bit
    1_4: {
        "prime": int(
            "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
            + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
            + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
            + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
            + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
            + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
            + "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
            + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
            + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
            + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
            + "15728E5A8AACAA68FFFFFFFFFFFFFFFF",
            base=1_6,
        ),
        "generator": 2,
    },
    # 3072-bit
    1_5: {
        "prime": int(
            "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
            + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
            + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
            + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
            + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
            + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
            + "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
            + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
            + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
            + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
            + "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64"
            + "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
            + "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B"
            + "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C"
            + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31"
            + "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF",
            base=1_6,
        ),
        "generator": 2,
    },
    # 4096-bit
    1_6: {
        "prime": int(
            "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
            + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
            + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
            + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
            + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
            + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
            + "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
            + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
            + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
            + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
            + "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64"
            + "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
            + "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B"
            + "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C"
            + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31"
            + "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7"
            + "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA"
            + "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6"
            + "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED"
            + "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9"
            + "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199"
            + "FFFFFFFFFFFFFFFF",
            base=1_6,
        ),
        "generator": 2,
    },
    # 6144-bit
    1_7: {
        "prime": int(
            "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08"
            + "8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B"
            + "302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9"
            + "A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE6"
            + "49286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8"
            + "FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D"
            + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C"
            + "180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718"
            + "3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D"
            + "04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7D"
            + "B3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D226"
            + "1AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200C"
            + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFC"
            + "E0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B26"
            + "99C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB"
            + "04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2"
            + "233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127"
            + "D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492"
            + "36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406"
            + "AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918"
            + "DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B33205151"
            + "2BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03"
            + "F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97F"
            + "BEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA"
            + "CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58B"
            + "B7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632"
            + "387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E"
            + "6DCC4024FFFFFFFFFFFFFFFF",
            base=1_6,
        ),
        "generator": 2,
    },
    # 8192-bit
    1_8: {
        "prime": int(
            "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
            + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
            + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
            + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
            + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
            + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
            + "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
            + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
            + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
            + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
            + "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64"
            + "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
            + "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B"
            + "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C"
            + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31"
            + "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7"
            + "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA"
            + "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6"
            + "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED"
            + "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9"
            + "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492"
            + "36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BD"
            + "F8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831"
            + "179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B"
            + "DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF"
            + "5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6"
            + "D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F3"
            + "23A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA"
            + "CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE328"
            + "06A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55C"
            + "DA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE"
            + "12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E4"
            + "38777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300"
            + "741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F568"
            + "3423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD9"
            + "22222E04A4037C0713EB57A81A23F0C73473FC646CEA306B"
            + "4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A"
            + "062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A36"
            + "4597E899A0255DC164F31CC50846851DF9AB48195DED7EA1"
            + "B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F92"
            + "4009438B481C6CD7889A002ED5EE382BC9190DA6FC026E47"
            + "9558E4475677E9AA9E3050E2765694DFC81F56E880B96E71"
            + "60C980DD98EDD3DFFFFFFFFFFFFFFFFF",
            base=1_6,
        ),
        "generator": 2,
    },
}

class       a		:







							def __init__(						self  :  Union[str, Any]      ,				snake_case__  :  int = 14 ):
								"""simple docstring"""







								if group not in primes:
									raise ValueError("Unsupported Group" )
								__lowerCAmelCase         =							primes[group]["prime"]
								__lowerCAmelCase         =							primes[group]["generator"]

								__lowerCAmelCase         =							int(hexlify(urandom(32 ) )      ,				base=16 )







							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								return hex(self.__private_key )[2:]







							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								__lowerCAmelCase         =							pow(self.generator      ,				self.__private_key      ,				self.prime )
								return hex(snake_case__ )[2:]







							def       UpperCAmelCase__					(						self  :  Dict      ,				snake_case__  :  int ):
								"""simple docstring"""







								return (
								    2 <= key <= self.prime - 2
								    and pow(snake_case__      ,				(self.prime - 1) // 2      ,				self.prime ) == 1
								)







							def       UpperCAmelCase__					(						self  :  int      ,				snake_case__  :  str ):
								"""simple docstring"""







								__lowerCAmelCase         =							int(snake_case__      ,				base=16 )
								if not self.is_valid_public_key(snake_case__ ):
									raise ValueError("Invalid public key" )
								__lowerCAmelCase         =							pow(snake_case__      ,				self.__private_key      ,				self.prime )
								return shaaaa(str(snake_case__ ).encode() ).hexdigest()







							@staticmethod
							def       UpperCAmelCase__					(						snake_case__  :  int      ,				snake_case__  :  int ):
								"""simple docstring"""







								return (
								    2 <= remote_public_key_str <= prime - 2
								    and pow(snake_case__      ,				(prime - 1) // 2      ,				snake_case__ ) == 1
								)







							@staticmethod
							def       UpperCAmelCase__					(						snake_case__  :  str      ,				snake_case__  :  str      ,				snake_case__  :  int = 14 ):
								"""simple docstring"""







								__lowerCAmelCase         =							int(snake_case__      ,				base=16 )
								__lowerCAmelCase         =							int(snake_case__      ,				base=16 )
								__lowerCAmelCase         =							primes[group]["prime"]
								if not DiffieHellman.is_valid_public_key_static(snake_case__      ,				snake_case__ ):
									raise ValueError("Invalid public key" )
								__lowerCAmelCase         =							pow(snake_case__      ,				snake_case__      ,				snake_case__ )
								return shaaaa(str(snake_case__ ).encode() ).hexdigest()


if __name__ == "__main__":
					import doctest

					doctest.testmod()






