Superdense Coding (SDC)

Max
students x students
9 min readMar 10, 2021

--

Hello everyone! While I was doing the TKS (The Knowledge Society) West Coast Focus Hackathon, I learned a lot of new and interesting things about Quantum Computing. One topic which I found very interesting was the Superdense Coding Protocol and Quantum Cryptography (article on that later!). In this article, I will talking about the Superdense Coding protocol. Enough of me blabbing; let’s dive in!

What is SDC?

SDC, or Superdense Coding, is a type of Quantum Cryptography in which two classical bits of information are transmitted using one quantum bit, or a qubit. Think of it as a flipped version of Quantum Teleportation, where we transmit one qubit using two classical bits; Quantum Teleportation basically destroys the quantum state of a qubit and recreates it in another location. Alright, that’s a brief overview of the Superdense Coding Protocol; let’s dive into how it works → the process!

The Process

Step 1: Preparation

A third party, let’s name him Jerry, prepares two qubits in the entangled state. An entangled state is when knowing something about one qubit gives us extra information about the second qubit. For example, knowing the state of one qubit can help us deduce the state of the second. There is also the one qubit which we will use to send the two classical bits of information. All three qubits start out in the |0⟩ state.

Next, a Hadamard gate is applied to the first qubit which Jerry prepares. For more information about quantum gates and what they do, I’ve linked my article on quantum gates at the bottom. Then, a Controlled-NOT gate is applied with the first qubit as the control and the second as the target. This creates a Bell Pair, and completes the preparation.

This is what our preparation circuit would look like:

Figure 1 → Preparation Circuit

Step 2: Sending the Qubit, aka Encoding

Now that we’ve successfully created our Bell Pair and entangled our two qubits, we can distribute them to our sender and receiver, who I’ll name Setare and Rohan, respectively. This is where our sender Setare sends two classical bits of information to our reciever Rohan. But first, we need to establish some rules depending on the message Setare wants to send. I’ve summarized the rules in the picture below as sadly, Medium doesn’t allow me to insert tables or use LaTeX code.

Figure 2 → Rules for Encoding

Once Setare has decided which message she wants to send, she simply applies the correct quantum gate(s) and sends her qubit to Rohan!

Step 3: Receiving the qubit, aka Decoding

Rohan receives Setare’s qubit, and uses his entangled qubit to decode Setare’s secret message, whatever that may be. The decoding process is actually quite simple. Essentially, Rohan does the opposite of what Jerry did in Step 1, applying the Controlled-NOT gate (with his qubit as the control and Setare’s qubit as the target), then the Hadamard gate. Finally, he measures both qubits to determine Setare’s message. The rules for decoding are as follows:

Figure 3 → Rules for Decoding

And that is the end of the SDC process! Now, let’s simulate this using IBM Quantum Experience. You can sign up for an account here.

Coding it up

First, we import all the modules we’ll need for this. Without them, we’d actually never be able to run programs for quantum computers on classical hardware, such as the device you’re currently using. The language, as you’ll see, is Python 3, so if you’re not too familiar with Python syntax, I recommend you check out some web tutorials, as I won’t be explaining all the syntax.

Figure 4 → Imports

Just a quick refresher, the from module_name import * syntax means we’re importing everything from the module named module_name, which is in this case qiskit, qiksit.visualization.

Now some of you with more experience may be wondering why I’m importing randint from random here, since it has nothing to do with the SDC protocol. The rationale behind this will be explained quite soon later on.

Figure 5 → Preparing the Entangled State

Now that we’ve imported everything we need, we move on to the next step, which is creating the entangled state. If you recall (or perhaps simply scroll up), we first apply a Hadamard gate, followed by a Controlled-Not gate. The function, named create_bell_pair does exactly this, as you can probably deduce from Figure 5.

Figure 6 → Encoding the Message

After preparation, Setare and Rohan recieve their qubits. Now, Setare wants to send her qubit to Rohan with some information. Following the rules given above, we create the code above — the function encode_message. The pass statement just means exactly what it sounds like: we pass, or do nothing. If the message Setare wants to send happens to be invalid or a bunch of junk characters, the last else statement tells her she can’t do that otherwise the system will break.

Figure 7 → Decoding the Message

Finally, after Rohan receives Setare’s qubit, he decodes it to figure out which message Setare decided to send him. Note that Setare can’t spam Rohan with a bunch of junk characters so the decoded message will always be something meaningful.

Putting Everything Together

Figure 8 → Putting Everything Together

At last, we’ve reached the most exciting part: putting everything together. First, we create a quantum circuit with two qubits (for Jerry), and create a Bell Pair with them. Next, we get Setare to choose a message to send to Rohan. Now, Setare is being particularly lazy, so she decides to choose a random message, hence the importing of the random module. Then she encodes her random message, sends it to Rohan, and Rohan decodes her message by measuring all the qubits. A visual representation of the circuit is shown below. Since there is an element of randomness in generating the message, the output circuit will vary.

Figure 9 → Sending Message 00
Figure 10 → Sending Message 01
Figure 11 → Sending Message 10
Figure 12 → Sending Message 11

And if we try to send an invalid message, this is what happens! Too bad Setare, looks like no Double Big Mac for you today!

Figure 13 → Sending Invalid Message

Simulation

We can simulate the circuit, whichever that may be, and get the results of the simulation, which should match up with what we expect. Since this is a simulation, the output probabilities should be 1.000 for measuring Setare’s message and 0.000 for all the other states. Now let’s test that prediction.

Figure 14 → Simulation (Code)

Well, it looks like we are indeed correct. The measurement results show a 1.000 chance of measuring 00 (which happens to be the random message Setare sent), and a 0.000 chance for everything else. But we’re not done yet! Why stop a simulating, when there are real quantum computers we can run our SDC Protocol program on?

Running on a REAL Quantum Computer

Figure 15 → Running on REAL Quantum Computer

A quick explanation about the code, we’ll be running this program 1024 times (you can set this to any integer between 1 and 8192) to get more accurate results, as seen in the Law of Large Numbers. Next, we just filter out the devices that have under two qubits, those that are simulators, and those that aren’t operational. Then we run our program on the least busy backend, since we won’t have to wait so long before our job gets executed. As you can see below, our job is queued, and we’ll have to wait for 86 other jobs to finish, which means we’ll be waiting a pretty long time, something like an hour or more, I’m guessing. We also got a Deprecation Warning, which just means some features will not be supported anymore.

Figure 16 → It’s going to be a looonnggg wait!

About two hours later, our job has finally run. The accuracy of the experiment was 93.26%, which is pretty high — the correct state was measured 93.26% of the time, so about 955 in 1024 times. The reason it measure the wrong state the other 69 times was because of noise, also known as things that mess up our experiment.

Figure 17 → Accuracy of Results

Of course, just knowing the accuracy of the results isn’t satisfactory enough, we want to see what the actual results are! Shown below is exactly that!

Figure 18 → Results

As you can see, we have a pretty high probability of measuring the state 11, which was the chosen random state. So we measured the correct state 761 times out of 1024, which is pretty high. The other three measurements are due to noise and errors in the quantum computations.

And that concludes the Superdense Coding Protocol program!

Extras and Resources

If you want to learn more about quantum computing, there are numerous courses out there on this topic! Below, I have listed a few (the list is not exhaustive).

There are also many courses on EdX and Udemy as well, so take a look!

Feedback?

Do you have any feedback for me? Is there anything that wasn’t clear enough? Please don’t hesitate to reach out and tell me on LinkedIn, feedback is always appreciated! In the meantime, stay tuned for more articles! I’ll be writing an article about Quantum Key Distribution soon, so watch out!

But Wait! What’s TKS? I wanna join!

TKS is honestly the most amazing program ever! The city directors are super-engaging and supportive. They’ve given awesome feedback to me and my friends, and helped with many projects and challenges, and give great advice as well. The Notion Playbooks they created are extremely valuable and full of useful tips, tricks, and more! I’ve learned so much about various technologies from their explores, hackathons, and challenges. I’ve made tons of friends who are ready to become unicorn people and leave an impact on the world, just like me. I recommend TKS to anyone who wants to make an impact on the world, and people who are passionate about future technologies.

TKS is a 10-month accelerator program that trains young people to maximize their ability to make an impact on the world. I’m grateful to be surrounded by a community of students working on technologies and solving global issues. If you’re aged 13–17 or know students aged 13–17 and are ambitious and curious, you/they will likely love the experience! Applications for next year are open! Check out the website: www.tks.world!

If you use my code “MACU18,” you can give ambitious students $200 off their tuition. Deadline to apply is April 5th.

Hello there! I’m a teenager who’s passionate about quantum computing, advanced transportation, blockchain and cryptocurrencies, and space technologies. If you want to follow along with my journey through TKS, why don’t you subscribe to my newsletter?

Feel like you’re about to jump into a rabbit-hole of reading these incredible articles?
Don’t worry, we feel the same way.
Not only can you jump into the rabbit hole with us, but we’ve got more than enough articles that’ll help you jump out ;)
For some of the best ideas on Medium from the youngest minds of the generation, visit students x students.

--

--

A person who is passionate about technologies such as Quantum Computing, Blockchain, and Machine Learning/AI. Currently working on a QCNN for Image Recognition!