Consider a circuit acting on $n\geq2p+1$ qubits. The first $p$ qubits encode some unknown state $|\psi\rangle$. Next $p$ qubits encode a fixed given basis state $|\phi\rangle=|\ldots f_2f_1f_0\rangle$. The $(2p+1)$th qubit is initialized in the $|0\rangle$ state. Using the standard set of gates, how can I check if $|\psi\rangle$ is equal to $|\phi\rangle$ and put the result of this comparison into the $2p+1$th qubit? (I wrote "$\geq$" in case we need ancillas).
I guess, the implementation has to do something with the SWAP test, but I don't want to do any measurements. Feels like my question is purely on classical logic, and there's nothing quantum about it.
Please note that my question is NOT about comparing two arbitrary states. One state is a known state from the computational basis.