
import copy
import os

import cva
import numpy as np
from matplotlib import pyplot as plt

class       a		:







							def __init__(						self  :  Dict ):
								"""simple docstring"""







								__lowerCAmelCase         =							""
								__lowerCAmelCase         =							""
								__lowerCAmelCase         =							[]
								__lowerCAmelCase         =							0
								__lowerCAmelCase         =							256
								__lowerCAmelCase         =							0
								__lowerCAmelCase         =							0
								__lowerCAmelCase         =							0
								__lowerCAmelCase         =							0







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







								__lowerCAmelCase         =							cva.imread(snake_case__      ,				0 )
								__lowerCAmelCase         =							copy.deepcopy(self.img )
								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							plt.hist(self.img.ravel()      ,				256      ,				[0, 256]      ,				label="x" )
								__lowerCAmelCase         =							np.sum(snake_case__ )
								for i in range(len(snake_case__ ) ):
									__lowerCAmelCase         =							x[i] / self.k
									self.sk += prk
									__lowerCAmelCase         =							(self.L - 1) * self.sk
									if self.rem != 0:
										__lowerCAmelCase         =							int(last % last )
									__lowerCAmelCase         =							int(last + 1 if self.rem >= 0.5 else last )
									self.last_list.append(snake_case__ )
									__lowerCAmelCase         =							int(np.ma.count(self.img ) / self.img[1].size )
									__lowerCAmelCase         =							self.img[1].size
								for i in range(self.number_of_cols ):
									for j in range(self.number_of_rows ):
										__lowerCAmelCase         =							self.img[j][i]
										if num != self.last_list[num]:
											__lowerCAmelCase         =							self.last_list[num]
								cva.imwrite("output_data/output.jpg"      ,				self.img )







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







								plt.hist(self.img.ravel()      ,				256      ,				[0, 256] )







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







								cva.imshow("Output-Image"      ,				self.img )
								cva.imshow("Input-Image"      ,				self.original_image )
								cva.waitKey(5_000 )
								cva.destroyAllWindows()


if __name__ == "__main__":
					UpperCamelCase_   	=	os.path.join(os.path.basename(__file__), "image_data/input.jpg")
					UpperCamelCase_   	=	ConstantStretch()
					stretcher.stretch(file_path)
					stretcher.plot_histogram()
					stretcher.show_image()








import numpy as np
import qiskit






def 		_UpperCAmelCase   (	UpperCamelCase:     int = 8			,							UpperCamelCase:     int | None = None  ):






	"""simple docstring"""


	__lowerCAmelCase         =							np.random.default_rng(seed=UpperCamelCase  )

	# Roughly 25% of the qubits will contribute to the key.
	# So we take more than we need.
	__lowerCAmelCase         =							6 * key_len
	# Measurement basis for Alice's qubits.
	__lowerCAmelCase         =							rng.integers(2			,							size=UpperCamelCase  )
	# The set of states Alice will prepare.
	__lowerCAmelCase         =							rng.integers(2			,							size=UpperCamelCase  )
	# Measurement basis for Bob's qubits.
	__lowerCAmelCase         =							rng.integers(2			,							size=UpperCamelCase  )

	# Quantum Circuit to simulate BB84
	__lowerCAmelCase         =							qiskit.QuantumCircuit(UpperCamelCase			,							name="BB84"  )

	# Alice prepares her qubits according to rules above.
	for index, _ in enumerate(UpperCamelCase  ):
		if alice_state[index] == 1:
			bbaa_circ.x(UpperCamelCase  )
		if alice_basis[index] == 1:
			bbaa_circ.h(UpperCamelCase  )
	bbaa_circ.barrier()

	# Bob measures the received qubits according to rules above.
	for index, _ in enumerate(UpperCamelCase  ):
		if bob_basis[index] == 1:
			bbaa_circ.h(UpperCamelCase  )

	bbaa_circ.barrier()
	bbaa_circ.measure_all()

	# Simulate the quantum circuit.
	__lowerCAmelCase         =							qiskit.Aer.get_backend("aer_simulator"  )
	# We only need to run one shot because the key is unique.
	# Multiple shots will produce the same key.
	__lowerCAmelCase         =							qiskit.execute(UpperCamelCase			,							UpperCamelCase			,							shots=1			,							seed_simulator=UpperCamelCase  )
	# Returns the result of measurement.
	__lowerCAmelCase         =							job.result().get_counts(UpperCamelCase  ).most_frequent()

	# Extracting the generated key from the simulation results.
	# Only keep measurement results where Alice and Bob chose the same basis.
	__lowerCAmelCase         =							"".join(
	    [
	        result_bit
	        for alice_basis_bit, bob_basis_bit, result_bit in zip(
	            UpperCamelCase			,							UpperCamelCase			,							UpperCamelCase  )
	        if alice_basis_bit == bob_basis_bit
	    ]  )

	# Get final key. Pad with 0 if too short, otherwise truncate.
	__lowerCAmelCase         =							gen_key[:key_len] if len(UpperCamelCase  ) >= key_len else gen_key.ljust(UpperCamelCase			,							"0"  )
	return key


if __name__ == "__main__":
					print(f'''The generated key is : {bbaa(8, seed=0)}''')
					from doctest import testmod

					testmod()






