




import argparse
import struct
import unittest
class 						UpperCAmelCase  :







						'''simple docstring'''





						def __init__(		self				:	Dict			,      __lowercase				:	bytes		):






							"""simple docstring"""






							snake_case_						       =	data

							# Initialize hash values
							snake_case_						       =	[
							    0X6a_09e_667,
							    0Xbb_67a_e85,
							    0X3c_6ef_372,
							    0Xa5_4ff_53a,
							    0X51_0e5_27f,
							    0X9b_056_88c,
							    0X1f_83d_9ab,
							    0X5b_e0c_d19,
							]

							# Initialize round constants
							snake_case_						       =	[
							    0X42_8a2_f98,
							    0X71_374_491,
							    0Xb5_c0f_bcf,
							    0Xe9_b5d_ba5,
							    0X39_56c_25b,
							    0X59_f11_1f1,
							    0X92_3f8_2a4,
							    0Xab_1c5_ed5,
							    0Xd8_07a_a98,
							    0X12_835_b01,
							    0X24_318_5be,
							    0X55_0c7_dc3,
							    0X72_be5_d74,
							    0X80_deb_1fe,
							    0X9b_dc0_6a7,
							    0Xc1_9bf_174,
							    0Xe4_9b6_9c1,
							    0Xef_be4_786,
							    0X0f_c19_dc6,
							    0X24_0ca_1cc,
							    0X2d_e92_c6f,
							    0X4a_748_4aa,
							    0X5c_b0a_9dc,
							    0X76_f98_8da,
							    0X98_3e5_152,
							    0Xa8_31c_66d,
							    0Xb0_032_7c8,
							    0Xbf_597_fc7,
							    0Xc6_e00_bf3,
							    0Xd5_a79_147,
							    0X06_ca6_351,
							    0X14_292_967,
							    0X27_b70_a85,
							    0X2e_1b2_138,
							    0X4d_2c6_dfc,
							    0X53_380_d13,
							    0X65_0a7_354,
							    0X76_6a0_abb,
							    0X81_c2c_92e,
							    0X92_722_c85,
							    0Xa2_bfe_8a1,
							    0Xa8_1a6_64b,
							    0Xc2_4b8_b70,
							    0Xc7_6c5_1a3,
							    0Xd1_92e_819,
							    0Xd6_990_624,
							    0Xf4_0e3_585,
							    0X10_6aa_070,
							    0X19_a4c_116,
							    0X1e_376_c08,
							    0X27_487_74c,
							    0X34_b0b_cb5,
							    0X39_1c0_cb3,
							    0X4e_d8a_a4a,
							    0X5b_9cc_a4f,
							    0X68_2e6_ff3,
							    0X74_8f8_2ee,
							    0X78_a56_36f,
							    0X84_c87_814,
							    0X8c_c70_208,
							    0X90_bef_ffa,
							    0Xa4_506_ceb,
							    0Xbe_f9a_3f7,
							    0Xc6_717_8f2,
							]

							snake_case_						       =	self.preprocessing(self.data		)
							self.final_hash()






						@staticmethod
						def 			snake_case__		(		__lowercase				:	bytes		):






							"""simple docstring"""






							snake_case_						       =	B"\x80" + (B"\x00" * (63 - (len(__lowercase		) + 8) % 64))
							snake_case_						       =	struct.pack(">Q"			,      (len(__lowercase		) * 8)		)
							return data + padding + big_endian_integer






						def 			snake_case__		(		self				:	List[Any]		):






							"""simple docstring"""






							snake_case_						       =	[
							    self.preprocessed_data[x : x + 64]
							    for x in range(0			,      len(self.preprocessed_data		)			,      64		)
							]

							for block in self.blocks:
								# Convert the given block into a list of 4 byte integers
								snake_case_						       =	list(struct.unpack(">16L"			,      __lowercase		)		)
								# add 48 0-ed integers
								words += [0] * 48

								snake_case_       , snake_case_       , snake_case_       , snake_case_       , snake_case_       , snake_case_       , snake_case_       , snake_case_						       =	self.hashes

								for index in range(0			,      64		):
									if index > 15:
										# modify the zero-ed indexes at the end of the array
										snake_case_						       =	(
										    self.ror(words[index - 15]			,      7		)
										    ^ self.ror(words[index - 15]			,      18		)
										    ^ (words[index - 15] >> 3)
										)
										snake_case_						       =	(
										    self.ror(words[index - 2]			,      17		)
										    ^ self.ror(words[index - 2]			,      19		)
										    ^ (words[index - 2] >> 10)
										)

										snake_case_						       =	(
										    words[index - 16] + sa + words[index - 7] + sa
										) % 0X100_000_000

									# Compression
									snake_case_						       =	self.ror(__lowercase			,      6		) ^ self.ror(__lowercase			,      11		) ^ self.ror(__lowercase			,      25		)
									snake_case_						       =	(e & f) ^ ((~e & 0Xff_fff_fff) & g)
									snake_case_						       =	(
									    h + sa + ch + self.round_constants[index] + words[index]
									) % 0X100_000_000
									snake_case_						       =	self.ror(__lowercase			,      2		) ^ self.ror(__lowercase			,      13		) ^ self.ror(__lowercase			,      22		)
									snake_case_						       =	(a & b) ^ (a & c) ^ (b & c)
									snake_case_						       =	(sa + maj) % 0X100_000_000

									snake_case_       , snake_case_       , snake_case_       , snake_case_       , snake_case_       , snake_case_       , snake_case_       , snake_case_						       =	(
									    g,
									    f,
									    e,
									    ((d + tempa) % 0X100_000_000),
									    c,
									    b,
									    a,
									    ((tempa + tempa) % 0X100_000_000),
									)

								snake_case_						       =	[a, b, c, d, e, f, g, h]

								# Modify final values
								snake_case_						       =	[
								    ((element + mutated_hash_values[index]) % 0X100_000_000)
								    for index, element in enumerate(self.hashes		)
								]

							snake_case_						       =	"".join([hex(__lowercase		)[2:].zfill(8		) for value in self.hashes]		)






						def 			snake_case__		(		self				:	Any			,      __lowercase				:	int			,      __lowercase				:	int		):






							"""simple docstring"""






							return 0Xff_fff_fff & (value << (32 - rotations)) | (value >> rotations)







class 						UpperCAmelCase  (							unittest.TestCase     ):







						'''simple docstring'''





						def 			snake_case__		(		self				:	int		):






							"""simple docstring"""






							import hashlib

							snake_case_						       =	bytes("Test String"			,      "utf-8"		)
							self.assertEqual(SHAaaa(__lowercase		).hash			,      hashlib.shaaaa(__lowercase		).hexdigest()		)







def 		lowerCamelCase__       (						):







	'''simple docstring'''





	import doctest

	doctest.testmod()

	snake_case_						       =	argparse.ArgumentParser()
	parser.add_argument(
	    "-s"	,      "--string"	,      dest="input_string"	,      default="Hello World!! Welcome to Cryptography"	,      help="Hash the string"	,      )
	parser.add_argument(
	    "-f"	,      "--file"	,      dest="input_file"	,      help="Hash contents of a file"				)

	snake_case_						       =	parser.parse_args()

	snake_case_						       =	args.input_string

	# hash input should be a bytestring
	if args.input_file:
		with open(args.input_file	,      "rb"				) as f:
			snake_case_						       =	f.read()
	else:
		snake_case_						       =	bytes(_A	,      "utf-8"				)

	print(SHAaaa(_A				).hash				)


if __name__ == "__main__":
		main()






import unittest

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

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    DebertaForMaskedLM,
		    DebertaForQuestionAnswering,
		    DebertaForSequenceClassification,
		    DebertaForTokenClassification,
		    DebertaModel,
		)
		from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST
class 						UpperCAmelCase  (							UpperCAmelCase__     ):







						'''simple docstring'''





						def __init__(		self				:	Dict			,      __lowercase				:	Any			,      __lowercase				:	str=13			,      __lowercase				:	Optional[Any]=7			,      __lowercase				:	Tuple=True			,      __lowercase				:	Optional[int]=True			,      __lowercase				:	List[str]=True			,      __lowercase				:	Dict=True			,      __lowercase				:	Any=99			,      __lowercase				:	Any=32			,      __lowercase				:	List[Any]=5			,      __lowercase				:	Any=4			,      __lowercase				:	List[str]=37			,      __lowercase				:	Union[str, Any]="gelu"			,      __lowercase				:	Union[str, Any]=0.1			,      __lowercase				:	str=0.1			,      __lowercase				:	List[str]=5_12			,      __lowercase				:	Tuple=16			,      __lowercase				:	List[str]=2			,      __lowercase				:	Tuple=0.02			,      __lowercase				:	Optional[Any]=False			,      __lowercase				:	Optional[int]=True			,      __lowercase				:	Union[str, Any]="None"			,      __lowercase				:	Union[str, Any]=3			,      __lowercase				:	int=4			,      __lowercase				:	Tuple=None			,      ):






							"""simple docstring"""






							snake_case_						       =	parent
							snake_case_						       =	batch_size
							snake_case_						       =	seq_length
							snake_case_						       =	is_training
							snake_case_						       =	use_input_mask
							snake_case_						       =	use_token_type_ids
							snake_case_						       =	use_labels
							snake_case_						       =	vocab_size
							snake_case_						       =	hidden_size
							snake_case_						       =	num_hidden_layers
							snake_case_						       =	num_attention_heads
							snake_case_						       =	intermediate_size
							snake_case_						       =	hidden_act
							snake_case_						       =	hidden_dropout_prob
							snake_case_						       =	attention_probs_dropout_prob
							snake_case_						       =	max_position_embeddings
							snake_case_						       =	type_vocab_size
							snake_case_						       =	type_sequence_label_size
							snake_case_						       =	initializer_range
							snake_case_						       =	num_labels
							snake_case_						       =	num_choices
							snake_case_						       =	relative_attention
							snake_case_						       =	position_biased_input
							snake_case_						       =	pos_att_type
							snake_case_						       =	scope






						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






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

							snake_case_						       =	None
							if self.use_input_mask:
								snake_case_						       =	ids_tensor([self.batch_size, self.seq_length]			,      vocab_size=2		)

							snake_case_						       =	None
							if self.use_token_type_ids:
								snake_case_						       =	ids_tensor([self.batch_size, self.seq_length]			,      self.type_vocab_size		)

							snake_case_						       =	None
							snake_case_						       =	None
							snake_case_						       =	None
							if self.use_labels:
								snake_case_						       =	ids_tensor([self.batch_size]			,      self.type_sequence_label_size		)
								snake_case_						       =	ids_tensor([self.batch_size, self.seq_length]			,      self.num_labels		)
								snake_case_						       =	ids_tensor([self.batch_size]			,      self.num_choices		)

							snake_case_						       =	self.get_config()

							return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






						def 			snake_case__		(		self				:	Optional[int]		):






							"""simple docstring"""






							return DebertaConfig(
							    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			,      type_vocab_size=self.type_vocab_size			,      initializer_range=self.initializer_range			,      relative_attention=self.relative_attention			,      position_biased_input=self.position_biased_input			,      pos_att_type=self.pos_att_type			,      )






						def 			snake_case__		(		self				:	int		):






							"""simple docstring"""






							snake_case_						       =	self.get_config()
							snake_case_						       =	3_00
							return config






						def 			snake_case__		(		self				:	List[Any]			,      __lowercase				:	List[Any]		):






							"""simple docstring"""






							self.parent.assertListEqual(list(result.loss.size()		)			,      []		)






						def 			snake_case__		(		self				:	List[str]			,      __lowercase				:	Tuple			,      __lowercase				:	Union[str, Any]			,      __lowercase				:	Tuple			,      __lowercase				:	Dict			,      __lowercase				:	str			,      __lowercase				:	Optional[int]			,      __lowercase				:	int		):






							"""simple docstring"""






							snake_case_						       =	DebertaModel(config=__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase		)[0]
							snake_case_						       =	model(__lowercase			,      token_type_ids=__lowercase		)[0]
							snake_case_						       =	model(__lowercase		)[0]

							self.parent.assertListEqual(list(sequence_output.size()		)			,      [self.batch_size, self.seq_length, self.hidden_size]		)






						def 			snake_case__		(		self				:	Any			,      __lowercase				:	Any			,      __lowercase				:	Dict			,      __lowercase				:	Any			,      __lowercase				:	Any			,      __lowercase				:	Tuple			,      __lowercase				:	Union[str, Any]			,      __lowercase				:	List[str]		):






							"""simple docstring"""






							snake_case_						       =	DebertaForMaskedLM(config=__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase			,      labels=__lowercase		)

							self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.seq_length, self.vocab_size)		)






						def 			snake_case__		(		self				:	List[str]			,      __lowercase				:	Tuple			,      __lowercase				:	List[str]			,      __lowercase				:	Dict			,      __lowercase				:	str			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Union[str, Any]		):






							"""simple docstring"""






							snake_case_						       =	self.num_labels
							snake_case_						       =	DebertaForSequenceClassification(__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase			,      labels=__lowercase		)
							self.parent.assertListEqual(list(result.logits.size()		)			,      [self.batch_size, self.num_labels]		)
							self.check_loss_output(__lowercase		)






						def 			snake_case__		(		self				:	List[Any]			,      __lowercase				:	List[str]			,      __lowercase				:	Any			,      __lowercase				:	List[Any]			,      __lowercase				:	str			,      __lowercase				:	List[str]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Optional[int]		):






							"""simple docstring"""






							snake_case_						       =	self.num_labels
							snake_case_						       =	DebertaForTokenClassification(config=__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase			,      labels=__lowercase		)
							self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.seq_length, self.num_labels)		)






						def 			snake_case__		(		self				:	List[str]			,      __lowercase				:	str			,      __lowercase				:	List[str]			,      __lowercase				:	Optional[int]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Union[str, Any]		):






							"""simple docstring"""






							snake_case_						       =	DebertaForQuestionAnswering(config=__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(
							    __lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase			,      start_positions=__lowercase			,      end_positions=__lowercase			,      )
							self.parent.assertEqual(result.start_logits.shape			,      (self.batch_size, self.seq_length)		)
							self.parent.assertEqual(result.end_logits.shape			,      (self.batch_size, self.seq_length)		)






						def 			snake_case__		(		self				:	Tuple		):






							"""simple docstring"""






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







@require_torch
class 						UpperCAmelCase  (							UpperCAmelCase__			,  UpperCAmelCase__			,  unittest.TestCase     ):







						'''simple docstring'''





						lowerCAmelCase_							=  (
						    (
						        DebertaModel,
						        DebertaForMaskedLM,
						        DebertaForSequenceClassification,
						        DebertaForTokenClassification,
						        DebertaForQuestionAnswering,
						    )
						    if is_torch_available()
						    else ()
						)
						lowerCAmelCase_							=  (
						    {
						        '''feature-extraction''': DebertaModel,
						        '''fill-mask''': DebertaForMaskedLM,
						        '''question-answering''': DebertaForQuestionAnswering,
						        '''text-classification''': DebertaForSequenceClassification,
						        '''token-classification''': DebertaForTokenClassification,
						        '''zero-shot''': DebertaForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)

						lowerCAmelCase_							=  True
						lowerCAmelCase_							=  False
						lowerCAmelCase_							=  False
						lowerCAmelCase_							=  False
						lowerCAmelCase_							=  False






						def 			snake_case__		(		self				:	int		):






							"""simple docstring"""






							snake_case_						       =	DebertaModelTester(self		)
							snake_case_						       =	ConfigTester(self			,      config_class=__lowercase			,      hidden_size=37		)






						def 			snake_case__		(		self				:	Optional[int]		):






							"""simple docstring"""






							self.config_tester.run_common_tests()






						def 			snake_case__		(		self				:	Dict		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_model(*__lowercase		)






						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_sequence_classification(*__lowercase		)






						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_masked_lm(*__lowercase		)






						def 			snake_case__		(		self				:	Optional[Any]		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_question_answering(*__lowercase		)






						def 			snake_case__		(		self				:	Optional[Any]		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_token_classification(*__lowercase		)






						@slow
						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								snake_case_						       =	DebertaModel.from_pretrained(__lowercase		)
								self.assertIsNotNone(__lowercase		)







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







						'''simple docstring'''





						@unittest.skip(reason="Model not available yet"		)
						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							pass






						@slow
						def 			snake_case__		(		self				:	Optional[int]		):






							"""simple docstring"""






							snake_case_						       =	DebertaModel.from_pretrained("microsoft/deberta-base"		)

							snake_case_						       =	torch.tensor([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]		)
							snake_case_						       =	torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
							with torch.no_grad():
								snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase		)[0]
							# compare the actual values for a slice.
							snake_case_						       =	torch.tensor(
							    [[[-0.5986, -0.8055, -0.8462], [1.4484, -0.9348, -0.8059], [0.3123, 0.0032, -1.4131]]]		)
							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]			,      __lowercase			,      atol=1E-4		)			,      f"{output[:, 1:4, 1:4]}"		)
