Solution (source code)

= Solution

Let $|\alpha\rangle=a|0\rangle+b|1\rangle$ be Alice's unknown qubit, and label her half of the shared <Bell state> by $A$ and Bob's by $B$. Alice applies a <Controlled-NOT gate> from the unknown qubit to $A$, then a <Hadamard gate> to the unknown qubit. The three-qubit state becomes
$$
\frac12\sum_{j,k\in\{0,1\}}|jk\rangle\,X^kZ^j|\alpha\rangle_B.
$$
Alice measures her two qubits in the computational basis and sends the two classical outcomes $(j,k)$ to Bob. Bob applies $Z^jX^k$, recovering $|\alpha\rangle$ with certainty. This is <quantum teleportation>; Alice never needs to know the state.

For the shared <GHZ state>, Charlie first applies a Hadamard gate to his qubit. Then
$$
\frac{|000\rangle+|111\rangle}{\sqrt2}
\longmapsto
\frac1{\sqrt2}\left(|\phi^+\rangle_{AB}|0\rangle_C
+|\phi^-\rangle_{AB}|1\rangle_C\right).
$$
Charlie measures in the computational basis. Outcome $0$ leaves Alice and Bob with $|\phi^+\rangle$; outcome $1$ leaves $|\phi^-\rangle$, which either party converts to $|\phi^+\rangle$ by applying $Z$ after Charlie reports the outcome. Thus
$$
\boxed{\text{Charlie creates the required shared Bell pair with probability one.}}
$$