Toffoli Gate Is Universal
The quantum Toffoli or CCNOT gate has three inputs and three outputs; if the first two qubits are both equal to 1, the gate inverts the third qubit; otherwise, it is left unchanged. The Toffoli gate is a universal logic gate, which means that any classical circuit can be constructed from Toffoli gates. We consider the NOT, AND, NAND and XOR gates and FANOUT, which can be simulated by a single Toffoli gate. (OR requires three Toffoli gates.) The right-hand side of the graphic shows the operation of the Toffoli gate for selected inputs , and . The kets marked in red are involved in the simulation of the classical gate shown on the left.[more]
After selecting which gate to simulate, follow the instructions on the graphic. For example, NOT requires that you set and .[less]
 G. Fano and S. M. Blinder, Twenty-First Century Quantum Mechanics, Berlin: Springer, 2018 pp. 222ff.
 M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary ed., Cambridge: Cambridge University Press, 2010 pp. 159ff.