






'''simple docstring'''





import numpy as np
import qiskit






def    lowerCamelCase_     (    lowercase__ = 8				,     lowercase__ = None):
	lowerCamelCase__  =     np.random.default_rng(seed=SCREAMING_SNAKE_CASE_)

	# 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=SCREAMING_SNAKE_CASE_)
	# The set of states Alice will prepare.
	lowerCamelCase__  =     rng.integers(2				,     size=SCREAMING_SNAKE_CASE_)
	# Measurement basis for Bob's qubits.
	lowerCamelCase__  =     rng.integers(2				,     size=SCREAMING_SNAKE_CASE_)

	# Quantum Circuit to simulate BB84
	lowerCamelCase__  =     qiskit.QuantumCircuit(SCREAMING_SNAKE_CASE_				,     name="BB84")

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

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

	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(SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_				,     shots=1				,     seed_simulator=SCREAMING_SNAKE_CASE_)
	# Returns the result of measurement.
	lowerCamelCase__  =     job.result().get_counts(SCREAMING_SNAKE_CASE_).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(
	            SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_)
	        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(SCREAMING_SNAKE_CASE_) >= key_len else gen_key.ljust(SCREAMING_SNAKE_CASE_				,     "0")
	return key


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

	testmod()









'''simple docstring'''





def    lowerCamelCase_     (    lowercase__				,     lowercase__				,     lowercase__):

 def update_area_of_max_square(lowercase__				,     lowercase__) -> int:
  # BASE CASE
  if row >= rows or col >= cols:
   return 0

  lowerCamelCase__  =     update_area_of_max_square(lowercase__				,     col + 1)
  lowerCamelCase__  =     update_area_of_max_square(row + 1				,     col + 1)
  lowerCamelCase__  =     update_area_of_max_square(row + 1				,     lowercase__)

  if mat[row][col]:
   lowerCamelCase__  =     1 + min([right, diagonal, down])
   lowerCamelCase__  =     max(largest_square_area[0]				,     lowercase__)
   return sub_problem_sol
  else:
   return 0

 lowerCamelCase__  =     [0]
 update_area_of_max_square(0				,     0)
 return largest_square_area[0]






def    lowerCamelCase_     (    lowercase__				,     lowercase__				,     lowercase__):

 def update_area_of_max_square_using_dp_array(
     lowercase__				,     lowercase__				,     lowercase__) -> int:
  if row >= rows or col >= cols:
   return 0
  if dp_array[row][col] != -1:
   return dp_array[row][col]

  lowerCamelCase__  =     update_area_of_max_square_using_dp_array(lowercase__				,     col + 1				,     lowercase__)
  lowerCamelCase__  =     update_area_of_max_square_using_dp_array(row + 1				,     col + 1				,     lowercase__)
  lowerCamelCase__  =     update_area_of_max_square_using_dp_array(row + 1				,     lowercase__				,     lowercase__)

  if mat[row][col]:
   lowerCamelCase__  =     1 + min([right, diagonal, down])
   lowerCamelCase__  =     max(largest_square_area[0]				,     lowercase__)
   lowerCamelCase__  =     sub_problem_sol
   return sub_problem_sol
  else:
   return 0

 lowerCamelCase__  =     [0]
 lowerCamelCase__  =     [[-1] * cols for _ in range(lowercase__)]
 update_area_of_max_square_using_dp_array(0				,     0				,     lowercase__)

 return largest_square_area[0]






def    lowerCamelCase_     (    lowercase__				,     lowercase__				,     lowercase__):
 lowerCamelCase__  =     [[0] * (cols + 1) for _ in range(rows + 1)]
 lowerCamelCase__  =     0
 for row in range(rows - 1				,     -1				,     -1):
  for col in range(cols - 1				,     -1				,     -1):
   lowerCamelCase__  =     dp_array[row][col + 1]
   lowerCamelCase__  =     dp_array[row + 1][col + 1]
   lowerCamelCase__  =     dp_array[row + 1][col]

   if mat[row][col] == 1:
    lowerCamelCase__  =     1 + min(lowercase__				,     lowercase__				,     lowercase__)
    lowerCamelCase__  =     max(dp_array[row][col]				,     lowercase__)
   else:
    lowerCamelCase__  =     0

 return largest_square_area






def    lowerCamelCase_     (    lowercase__				,     lowercase__				,     lowercase__):
 lowerCamelCase__  =     [0] * (cols + 1)
 lowerCamelCase__  =     [0] * (cols + 1)
 lowerCamelCase__  =     0
 for row in range(rows - 1				,     -1				,     -1):
  for col in range(cols - 1				,     -1				,     -1):
   lowerCamelCase__  =     current_row[col + 1]
   lowerCamelCase__  =     next_row[col + 1]
   lowerCamelCase__  =     next_row[col]

   if mat[row][col] == 1:
    lowerCamelCase__  =     1 + min(lowercase__				,     lowercase__				,     lowercase__)
    lowerCamelCase__  =     max(current_row[col]				,     lowercase__)
   else:
    lowerCamelCase__  =     0
  lowerCamelCase__  =     current_row

 return largest_square_area


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 print(largest_square_area_in_matrix_bottom_up(2, 2, [[1, 1], [1, 1]]))

