Reader small image

You're reading from  Quantum Computing Algorithms

Product typeBook
Published inSep 2023
PublisherPackt
ISBN-139781804617373
Edition1st Edition
Right arrow
Author (1)
Barry Burd
Barry Burd
author image
Barry Burd

Barry Burd received a master's degree in computer science at Rutgers University and a Ph.D. in mathematics at the University of Illinois. As a teaching assistant in Champaign–Urbana, Illinois, he was elected five times to the university-wide List of Teachers Ranked as Excellent by Their Students. Since 1980, Dr. Burd has been a professor in the department of mathematics and computer science at Drew University in Madison, New Jersey. He has spoken at conferences in the United States, Europe, Australia, and Asia. In 2020, he was honored to be named a Java Champion. Dr. Burd lives in Madison, New Jersey, USA, where he spends most of his waking hours in front of a computer screen.
Read more about Barry Burd

Right arrow

A Fanciful Tale about Cryptography

In our modern society, information privacy is essential. If people knew your credit card number, you could lose lots of money. If your medical records became public, a potential employer may decide not to hire you. If a foolish remark you made when you were ten years old circulated on social media sites, you could be banned from public office. And if a snooper catches you sending certain kinds of sell all my shares emails, you could go to jail for years and years.

Methods for sending secret messages have been around for millennia. One of the older methods is called the Caesar Cipher because it’s named after the emperor himself – Julius Caesar. But secret messages can be intercepted and decrypted. One of the most famous cases took place during World War II when a team of researchers led by Alan Turing created a device to decrypt German military communications.

A common way to encrypt a message is to mix the message’s content...

Technical requirements

The code for this chapter can be found online on GitHub: https://github.com/PacktPublishing/Quantum-Computing-Algorithms.

Sharing secrets

Alice and Bob want to share a secret. They don’t care what the secret means – the secret doesn’t have to mean anything at all. The secret might be “Bob once spit in Alice’s soup” or it might be “3*%Uw4YM^i44Sq.” The content doesn’t matter, so long as no one else knows it.

So, Alice randomly generates 20 bits and sends them to Bob. (See Figure 5.1.)

Figure 5.1 – Alice sends bits to Bob

Figure 5.1 – Alice sends bits to Bob

What they don’t know is that an eavesdropper (named Eve) listens in on the line. Eve makes copies of the bits and sends them to Bob. (See Figure 5.2.)

Figure 5.2 – Eve snoops

Figure 5.2 – Eve snoops

Sorry, Alice. Your bits aren’t secret. Back to the drawing board!

Adding Hadamard gates

Alice knows all about quantum computing. So, before she sends her bits, she applies the Hadamard operator to each one. Since the Hadamard operator is its own inverse, Bob...

Is the BB84 algorithm useful?

In the previous section, Alice and Bob formed a randomly generated secret. Both Alice and Bob know 10100 or whatever other sequence their BB84 algorithm generated. But what good is that? If Alice can’t decide exactly what she wants to say to Bob, why should she bother saying anything at all?

The answer lies in what Alice does with the randomly generated secret. By combining her randomly generated secret with some meaningful information, Alice can form a sequence of characters that’s meaningful to Bob but meaningless to an eavesdropper.

Here’s some terminology:

  • The randomly generated secret is called a key.

For example, in the previous section, Alice and Bob created the key 10100.

  • The meaningful information that must be kept from prying eyes is called plaintext.

Imagine that Alice wants to send the word Stop! to Bob. Alice doesn’t want anyone else to read this message. The word Stop! is an...

You can’t copy a qubit

The BB84 algorithm works because no eavesdropper can make a copy of a qubit’s state. Imagine that Eve intercepts one of Alice’s qubits, makes a measurement, and gets a value of 1. Eve has no way of knowing whether the qubit she measured was in the |1 state, the state, the state, or some other exotic in-between state. So, Eve doesn’t know exactly what to forward to Bob.

But wait! Can we be sure that Eve has no way to make a copy of Alice’s qubit? Yes, we can. The No-Cloning theorem shows that assuming that qubits can be copied leads to a nasty contradiction.

Let’s start by agreeing on three properties of tensor products:

  • For any three matrices, x, y, and z, a left distributive law holds – that is, {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mi>x</mi><mo>&#xA0;</mo><mo>&#x2297;</mo><mo>&#xA0;</mo><mfenced><mrow><mi>y</mi><mo>&#xA0;</mo><mo>+</mo><mo>&#xA0;</mo><mi>z</mi></mrow></mfenced><mo>&#xA0;</mo><mo>=</mo><mo>&#xA0;</mo><mfenced><mrow><mi>x</mi><mo>&#xA0;</mo><mo>&#x2297;</mo><mo>&#xA0;</mo><mi>y</mi></mrow></mfenced><mo>&#xA0;</mo><mo>+</mo><mo>&#xA0;</mo><mfenced><mrow><mi>x</mi><mo>&#xA0;</mo><mo>&#x2297;</mo><mo>&#xA0;</mo><mi>z</mi></mrow></mfenced></mstyle></math>"}.

You can write out a formal proof of this fact, but I always like to test with a simple example:

An example is never as good as proof, but an example helps us...

Qiskit code for the BB84 algorithm

Our BB84 simulation is a 150-line program (give or take a few lines). To make the program comprehensible, we’ll divide it into 16 function definitions. Let’s start with the imports and constant declarations:

import randomfrom qiskit import QuantumCircuit, QuantumRegister, \
    ClassicalRegister, Aer, execute
NUMBER_OF_CIRCUITS = 100
DOES_EVE_EXIST = False
CHECK_MARK = u'\u2713'

According to these declarations, we’ll be creating 100 circuits – one for each of the qubits that Alice sends to Bob. We’ll simulate a situation in which no eavesdropper exists. For convenience, we will declare CHECK_MARK to be the Unicode symbol.

The main flow of execution looks like this:

circuits = create_circuits(NUMBER_OF_CIRCUITS,                           DOES_EVE_EXIST...

Getting more information about a circuit

In the previous section, we used the QuantumCircuit class’s count_ops function to find out whether Alice applies an X gate and whether the circuit has an even or odd number of Hadamard gates. Sometimes, you need to discover more details about an existing circuit. For cases of this kind, you can use the QuantumCircuit class’s data attribute. A circuit’s data attribute contains enough information to recreate the circuit in its entirety. Take, for example, the circuit shown in Figure 5.21:

Figure 5.21 – The smallest circuit returned by any call to make_new_circuit

Figure 5.21 – The smallest circuit returned by any call to make_new_circuit

If you print this circuit’s data attribute, and you add your own line breaks, you will see the following information:

[  CircuitInstruction(
    operation=Instruction(
      name='swap', num_qubits=2, num_clbits=0, params=[]
    ...

Summary

Using classical communications, any information that you send over a network can be intercepted and read by a malicious agent. This includes meaningful information such as your credit card number, but it also includes any randomly generated key that you use to encrypt the meaningful information. One way to achieve secure message transmission is for both the sender and the receiver to have information without ever transmitting that information over a network. We know of no way to do this with credit card numbers or any other meaningful information. But, using the BB84 algorithm, the sender and receiver can cooperatively create a random key that’s known only to the two of them. This random key is never transmitted along network lines.

The BB84 algorithm depends on one important fact: you can’t clone a qubit. If you get a qubit in some arbitrary state, , you can’t measure the values of {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mi>&#x3B1;</mi></mstyle></math>"} and {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mi>&#x3B2;</mi></mstyle></math>"} to end up with two qubits in the same state. But what if you...

Questions

  1. Figure 5.6 contains lots of little details. Keep me honest by checking to make sure that the H letters, question marks, zeros, ones, and arrows are all placed correctly on Bob’s side of the figure.
  2. Repeat your work from Question 1, this time verifying the ones, zeros, and question marks in Eve’s column in Figure 5.10.
  3. In carrying out the BB84 algorithm, Alice and Bob share some information out in the open. Bob shares all of his Hadamard choices, Alice announces which qubits are Hadamard agreement qubits, and Bob displays half of his Hadamard agreement bits. Justify the claim that making this information public doesn’t help Eve discover the key.
  4. Make up an example to build your intuitions about the right distributive law for tensor products: {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mfenced><mrow><mi>x</mi><mo>&#xA0;</mo><mo>+</mo><mo>&#xA0;</mo><mi>y</mi></mrow></mfenced><mo>&#xA0;</mo><mo>&#x2297;</mo><mo>&#xA0;</mo><mi>z</mi><mo>&#xA0;</mo><mo>=</mo><mo>&#xA0;</mo><mfenced><mrow><mi>x</mi><mo>&#xA0;</mo><mo>&#x2297;</mo><mo>&#xA0;</mo><mi>z</mi></mrow></mfenced><mo>&#xA0;</mo><mo>+</mo><mo>&#xA0;</mo><mfenced><mrow><mi>y</mi><mo>&#xA0;</mo><mo>&#x2297;</mo><mo>&#xA0;</mo><mi>z</mi></mrow></mfenced></mstyle></math>"}.
  5. We began this chapter’s You can’t copy a qubit section by stating three laws for tensor products. Do we use all three of these laws in our argument about the truth of the No-Cloning...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Quantum Computing Algorithms
Published in: Sep 2023Publisher: PacktISBN-13: 9781804617373
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Barry Burd

Barry Burd received a master's degree in computer science at Rutgers University and a Ph.D. in mathematics at the University of Illinois. As a teaching assistant in Champaign–Urbana, Illinois, he was elected five times to the university-wide List of Teachers Ranked as Excellent by Their Students. Since 1980, Dr. Burd has been a professor in the department of mathematics and computer science at Drew University in Madison, New Jersey. He has spoken at conferences in the United States, Europe, Australia, and Asia. In 2020, he was honored to be named a Java Champion. Dr. Burd lives in Madison, New Jersey, USA, where he spends most of his waking hours in front of a computer screen.
Read more about Barry Burd