# Bernstein-Vazirani algorithm to find whether the secret has a one at a specific location

In the Bernstein- Vazirani Algorithm, we check whether the secret number has a '1' at a specific index of the number. If it's 1, we apply a CNOT gate, and then the algorithm gives the accurate value of the secret number. So, my question is this, if we can ask the black box whether the secret number has a one at a specific location, doesn't that gives me the number without even using the algorithm?

Now, I know this sounds incredibly stupid, and I am missing something very obvious but I can't seem to figure out what that is. Thanx in advance!

• Why do you limit the checking of the secret number to looking for a 1 at a specific index? Feb 1, 2023 at 13:48
• Sorry, I did not understand your question. What I meant is if we can say the black box the contains of its number( whether it's 0 or 1), what's the use of the algorithm? Feb 1, 2023 at 13:55
• What are you basing yourself on when you say "if we can say the black box the contains of its number"? Can you put a source you're basing this on, an example you saw maybe?
– Lena
Feb 1, 2023 at 14:08
• Well in the qiskit textbook, the algorithm they have used is....\\ $$\text{ if s[q] == '0': \\ bv_circuit.i(q) \\ else: \\ bv_circuit.cx(q, n)}$$ where s is hidden/secret binary code we hope to find. So, aren't we asking it the question whether you have a '1' in a specific location or not? Feb 1, 2023 at 14:11
• I feel like your confusion comes from the fact that the example is not an actual practical case of the BV algorithm and more of a "verification protocol" of the theoretical algorithm. As you can see in this example we say "ok we have this secret let's check that the associated circuit gives the answer we expect" rather than "we have a black box it is of the form f(x) = x.s and we have to find s", do you understand the difference?
– Lena
Feb 1, 2023 at 14:36

You have to separate out the implementation of the black box from the rest of the circuit. If we implement this ourselves when we're not actually given a black box, we have to create the circuit for the black box ourselves, and so we have to know the secret $$s$$. This is what you're seeing.
However, the scenario that's supposed to happen is that somebody else is implementing the black box. They know the secret but we do not. We cannot see how they are implementing the circuit or anything. We can just supply input states and they give us back output states. From what we see of those, we have to figure out what the secret $$s$$ is.