domingo, 10 de maio de 2020

The SWAP Gate and Quantum Hacking

The SWAP gate swaps the quantum register contents from one register to another, namely:

SWAP |00> = |00>
SWAP |01> = |10>
SWAP |10> = |01>
SWAP |11> = |11>

Thus, while, in the case where the two patterns coincide (‘00’ and ‘11’) the pattern is unchanged, in the case where the two patterns do not match the contents are swapped.

Now, we can take advantage of quantum parallelism to move a qubit dynamical pattern from one register to another, namely, let us consider two quantum registers, one for Alice and another one for Bob with the following configurations:

|Alice> = a|0>+b|1>
|Bob> = |0>

The joint Alice + Bob ket vector leads to:

|Alice,Bob> = a|00>+b|10>

If we apply the SWAP gate, we get:

SWAP|Alice,Bob> = a|00>+b|01>

So that the quantum register for Alice has Bob’s initial configuration and Bob has Alice’s:

|Alice> = |0>
|Bob> = a|0>+b|1>

Now, let us turn this into a quantum communications game between quantum registers and assume that Alice wants to Bob’s register to receive either the logical value of 0 or the logical value of 1, but we assume that Alice wants to encrypt her message for Bob.

While in the past posts we have represented these games in terms of a single circuit that simulates a quantum communication process with photons sent from one place to another, we are now playing a different game in that the encryption and communication takes place inside a same quantum computer.

In this case, the communication protocol in which both Alice and Bob start at |0> is as follows:

1. Alice first places her quantum register in the logical pattern she wants to send, which is either s=0 or s=1, this leads to the change:

|00> -> |s0>

2. Alice applies the Haddamard transform to her register, while Bob does nothing, the configuration for the Alice+Bob’s registers is:

(H|s>)|0>

3. Alice applies the SWAP gate to both registers (this is the communication stage), now the configuration for the Alice+Bob’s registers is:

|0>(H|s>)

4. Bob now just has to apply the Haddamard transform to his quantum register in order to invert the Haddamard transform and he has Alice’s intended message, with Alice's pattern being |0>:

|0>|s>

The circuit built on IBM’s OnepQASM for transmitting the message '0' is given by:



If we run this circuit with 1024 repeated experiments on the ibmq_qasm_simulator, we find that Bob indeed gets the message '0' 100% of the time and Alice's register has the measured logical value of '0' 100%, of the time, the results are available at the website: https://quantum-computing.ibm.com/results/5eb7d4f29fbdcb001877673b (as a note, the results must be read from the end to the beginning, which means that Alice's register is the rightmost and Bob the leftmost, which is inverted with respect to the ket order that we are using above).

The circuit for transmitting the message '1' is given by:

Again, if we run the circuit on the ibmq_qasm_simulator, again, we find that Alice has the measured logical value of '0' and Bob gets the intended message '1', the results are available at the website: https://quantum-computing.ibm.com/results/5eb7db1b955f050018c70cad.

What about the hacker called Eve? 

If Eve tries to measure Bob’s register, then, she gets noise, with Alice and Bob finding out that Eve has hacked the circuit. The hacked circuit, for the case where Alice wants to sent '1' is given by (the adaptation to the case where Alice sends a '0' just needs to erase the initial X gate):




Running again this circuit on the ibmq_qasm_simulator, for 1024 trials, leads to the following result:




The results show that Alice's measurement is '0' every time, so that on her end she does not find out that the circuit was hacked, Bob, however, like Eve, get a 50/50 distribution.

So the circuit is protected against an intermediate quantum measurement by Eve.

The protection against the measurement hack stems from a characteristic of quantum mechanics, namely, the middle measurement by Eve destroys the quantum interference effects and this allows Bob to know that the circuit has been hacked.

There is, however, a quantum hacking strategy using a quantum malware defined in terms of a sequence of gates for this circuit without any kind of quantum measurement being performed, in this case, Eve can apply the Haddamard transform on Bob's register followed by an X gate and a second Haddamard transform, the circuit below illustrates the case for when Alice wants to send a '1' to Bob, we placed Eve's quantum malware algorithm between two barriers (if, instead of '1', Alice sends a '0' then all one has to do is erase the first X gate):

Running this circuit on the ibmq_qasm_simulator, 100% of the time Alice's quantum register is measured to '0' and Bob's quantum register is also measured to '0', which was not Alice's initial message, so that Eve's "quantum malware" has hacked the circuit and changed the message sent.

The following histograms show the results of running the above circuit on an actual quantum computer, in this case we used ibmq_essex.




From the results we can see that 86.719% of the time Alice measures a '0' and Bob measures a '0', which is the result of the hacked circuit, the other measured patterns for the respective quantum registers are the result of the noise in the actual quantum computer.

If we erase the first X gate (Alice wants to send a '0'), and also run the circuit on the ibmq_essex device, then, as shown in the results below, the dominant pattern is also that of the circuit, in this case, leading to a pattern in which Alice measures her register to '0' and Bob measures his register to '1'.




If we consider both experiments and just calculate how many times Bob receives the wrong message (as intended by Eve) we get, in the first case, 86.719% (from the circuit) + 1.563% (from noise) = 88.282% as the percentage of cases where Bob measures a '0' instead of the value '1' "sent" by Alice. In the second case, we get 76.563% (from the circuit) + 4.980% (from noise) = 81.543% as the percentage of cases where Bob measures a '1' instead of the value '0' "sent" by Alice.