Intro To Quantum Cryptology

Totally_Not_A_Haxxer
54 min readMay 23, 2023

--

Introduction

Something we all as computer scientists or security researchers have heard of at least once was the Alice, Eve and Bob situation. This scenario is one of the most common representations and ways to introduce a person to Quantum Cryptology which is cryptography with the implementation of quantum mechanics and mathematics. In this article Intro To Quantum Cryptology we will be discussing this situation and give you a base understanding of how this works then implement this using the Go programming language. This article will not be going heavily deep into it but it will touch base on some algorithms, understandings of the situations and why we use specific algorithms and protocols using quantum mechanics over standard mechanics. Before we continue, I might have to let you in on this but you may be asking, why are we choosing to implement this in Golang? Personally speaking, I chose Golang for this because of two major points which are shown below

  • Irony: While quantum mechanics is not new to the world and has been around for quite a while, it is ironic that we choose a language developed in the early 2000’s to execute something quite what is considered “legacy” ( QKD ).
  • Base: Golang has an amazing mathematical base, type system, syntax and easy to read and use core! Despite us using a language like Go it is important to note that in order to fully represent QKD we would need actual quantum computers or quantum SDK’s that allow for the virtualization of quantum circuits like Quiskit which is a SDK for quantum computing developed by IBM to represent and simulate the behavior of entangled quantum bits (Qubits).

Terms and Phrases Used

This article like all other technical articles will go much more deeper into the types and programs being built to represent specific states and flows. So, to make the article and writing time much more faster I have chosen to make a few abbreviation and also define some terms before you get into the article shown below.

  • Alice and Bob scenario → Bob has a letter he wants to send to Alice, bob then puts his message and letter inside a tiny box with a padlock on it where only bob and Alice share the same key to that same box. Because Alice and bob share the same key the middleman or in this case, the mailman and anyone else delivering that mail can not open that box because they do not share the same key. This situation is easy to represent specific algorithms or representations in cryptography similar to QKD because it is easy to understand and follow for those who do not know much about cryptography. This scenario may also be modified and flexed in specific cases to make it more understandable for specific algorithms.
  • Cryptography → Cryptography is the study and practice of securing specific forms of communication from unauthorized access. The Alice and Bob scenario is a perfect example to explain how cryptography works. The whole idea is encrypting messages to ensure they are safe from people who should not have access to the message.
  • QKD → Quantum Key Distribution otherwise known as QKD is a cryptographic algorithm that implements parts of quantum mechanics to ensure that a key can not be exposed.
  • Channels → Channels are exactly what they are, in this context when we use the term channel or channels we are talking about a communication channel between two parties which can be a client and server or server and client.
  • Medium → A medium in the context of this article will be the medium of transporting data and information over a channel like the internet. In our case, the internet is considered a channel and the medium of transporting the data can differ from physical connections or digital transmission like WiFi and Bluetooth.
  • Qubit → A quantum equivalent of a standard computational bit. A quantum bit is used in quantum computers to represent or hold quantum information. Qubits are typically able to exist in a superposition of both states simultaneously unlike classical bits which can exist in only the 0 or 1 state at a given time. In order to represent a quantum bit there is a need for a quantum gate.
  • Quantum Gate → A quantum gate is the quantum representation or rather version of a standard computational / logical gate within standard computers. Quantum gates are much more different than logical gates where instead of being represented using truth tables and logical symbols they rather are represented by matrices. Quantum gates also have different effects on qubits depending on the gate. For example, Hadamard hate will place a qubit into a superposition of both 0 and 1 states by changing the probabilities of measuring 0 or 1 but the CNOT gate ( Controlled NOT gate ) is a two qubit gate that flips the second qubit ( typically the target ) if the first qubit ( the control ) is in the state 1. These gates all have different affects on a qubits state or a different end result and many other gates exist such as Phase gates, pauli gates and so on from there.
  • Photon → A photon for anyone who did not take or remember much from their science class is a fundamental particle that carries electromagnetic radiation including radio waves, X-rays and light. In the context of quantum computing photons carry visible light and they are used to transmit data. In the case of quantum computing, photons are represented by wave functions.
  • Wave Functions / Q-State → A wave function which is typically referred to as a quantum state is a mathematical description of the probability amplitude of a particles POS ( position ), momentum or other various properties. These are used in quantum computing to help with describing the quantum state of a Qubit ( The quantum equivalent of a traditional computational bit ) such as its probability of measuring a particular state of the qubit such as its spin or polarization. In general, wave functions are used to execute specific quantum operations.
  • Superposition → In quantum mechanics the superposition of a quantum computer is the ability of a quantum computer to exist in multiple states simultaneously. This means that the quantum system can be in a superposition of two or more possible states at the same time where each state has a certain probability of being observed when the system is measured.
  • Polarization → In quantum mechanics, polarization is a fundamental property of photons, which are the quantum particles that make up electromagnetic waves, including light. These photons have a property called spin, which can be thought of as the intrinsic angular momentum of the particle. The spin of a photon can be in one of two possible states, which correspond to opposite polarization's. One of the most common applications of the polarization is in QKD. The polarization of a photon is used to transmit the secret key using something known as quantum entanglement. In QKD the polarization of the photons is used to transmit the key between two parties over the insecure channel.
  • Quantum Entanglement → Quantum-Entanglement in quantum mechanics is a concept that describes a phenomenon in which two or more quantum systems become so strongly correlated that their states become intertwined and cannot be described independently. In a sense, two parties are entangled and the state of one particle will be linked to the state of the other no matter how far they are in a space. A good example of this is that if any measurement or manipulation is executed on one state or particle it will instantaneously affect the state of the other particle even if they are separated by extreme distances.

Now that we got some terms chomped down we can go ahead and take a deep dive into this article and go right down the isle of quantum computing, quantum security and quantum cryptology.

Quantum Computer Science | Quantum Cryptology

As the world of technology continues to grow along with the world of cyber space warfare operations, the bad actors on the other side also seem to grow with it. I mean, that is pretty expected isn't it? You do not see much bank robbers robbing banks with muskets now do you hahahah! Alright enough jokes. As attackers become much more advanced and use or discover much more stealthy techniques, the defenders must also become as equally or if not more advanced than the attackers. With the recent merge of the two worlds of quantum cryptography and cyber security, we have seen some interesting changes in this world. The first most noticeable change is the cryptography changes. Generally speaking, quantum is not used yet in cyber security or the realm of even physical security due to how far and how vastly different they are from traditional computers. However, this does not mean that we can prepare for it! In this section we will talk about the applications of quantum cryptology and quantum computer science where each section has its own defined purpose. When we finish this section we will go further into detail on quantum key distribution ( QKD ) and representing it using the Fortran programming language.

Quantum Computer Science | A slight breakdown

Before we dive deep into quantum cryptology and before we actually go into how everything works, it is important that we get a grasp on what exactly ends up being quantum computer science. Quantum computer science is the study that combines quantum mechanics into computer science to explore potential use of quantum computers to solve much more complex problems that classical computers can not solve. Now, right away we can not say that just because it has the word quantum means its going to do better or be much more safer and easier to work with than classical computers. That there is a huge misconception of what quantum fields are, sure quantum fields are MUCH more complex and much more deeper than classical fields of science such as mathematics, computer science etc but they also have their problems ( we will go into this when we talk about QKD and BB84 protocols ). Quantum computing takes these studies and mashes them together to create a whole new realm known as quantum computer science. This combination allows for a whole new world of algorithms, representations of classical computational parts like logical gates, bits, memory and other forms of hard ended parts. In the field of quantum computer science is a much more deeper realm where the algorithms, tools and idea’s developed can only be truly represented using quantum computers which have their own form of hardware. In order to represent Qubit’s, Quantum-Gates, Quantum superposition and many other large parts of quantum computing in classical computers, we can use SDK’s ( Software Development Kits ) like Quiskit to simulate the behavior of specific quantum results. In quantum mechanics and quantum science most standard mathematics or understanding of physics nearly becomes completely void due to the idea’s and work and different forms that quantum science ends up spawning. While quantum science voids all of the work that took centuries for groups of people to come up with it still has its sides that use standard fields to build off of new idea’s. Before I bore you with the technical details lets dive into something fun like quantum mechanics which is a heavily applied field in quantum computing. In quantum mechanics there are weird tables and idea’s of the field or rather abilities such as the ability to predict the existence of phenomena such as tunneling. Tunneling occurs when a particle can pass through a barrier even though it does not have enough energy to over come the barrier classically. The effect is critical for understanding the behavior of electrons in something known as a semiconductor (Semiconductors are a class of materials that have electrical conductivity between that of conductors (such as metals) and insulators (such as ceramics)) and other electronic devices. Now within quantum science and the development of these predictions or these new idea’s also comes new idea’s in the cyber security space and the application or idea of merging traditional computers with general quantum computers which introduces our next section.

The bleeding of quantum computing into general cyber security

The quantum field and the standard computer fields as we have already established are completely different from each other. While quantum computers and fields of quantum computing take idea’s of standard computing and apply them or re-make them by taking methods or idea’s from quantum mechanics and applying them to general computing systems it still does not mean that they can directly work together. However, despite the idea of quantum computers working directly with standard computers has not been fully proven outside of simulation, other people still want to make efforts to tie the two branches into each other. Because of this, many questions have risen from the people within the public eye and in standard computer science related fields such as cyber security, development and designers. These questions typically fall under the following…

  • How will quantum shape the future?
  • How will quantum shape or work with cyber-security
  • How will quantum change the world of standard computing

The answer to these questions is all the same, it wont. Quantum computing is so different and so vast and advanced to where it ( as of writing this ) can not actually change anything within the standard computing world or cyber space as we are talking on standard computers and quantum computers operate completely differently. Despite this, we have already seen the idea of how quantum computing was formed ( by merging general computer science with quantum mechanics and mathematics ) so what is stopping it from actually bleeding into the life of the cyber security field or rather what is stopping it from merging both quantum mechanics and cyber security? Truthfully speaking, nothing, because it already has. Within the last few decades, standard computing has changed alot from newer methods to breaks in the technological realm causing the entire side of the cyber space to collapse and be built up stronger. Within those changes and within those say few decades, cryptographic and quantum experts cut to the chase of modern day cryptography and decided to make a change and purpose something utterly mind-blowing ( for its time ). Some day at some random time in 1984, a intelligent quantum mechanics researchers and physicists by the names or Charles Bennett and Gilles Brassard proposed the idea of QKD commonly known as Quantum Key Distribution in their paper Quantum cryptography: Public key distribution and coin tossing. Within this paper both researchers introduced and laid out the core principals of quantum cryptography and QKD and its potential to protect data over an insecure channel based on the laws of quantum mechanics. Since their paper on quantum cryptography, the field of QKD has changed and has had new forms of development in the side of its protocols and as a side result, quantum hardware also changed because of that research. In today’s realm QKD is recognized as one of the most promising applications of QIS ( Quantum Information Science ) with potential applications in fields ranging from finance to healthcare and even military communication. Back in the early to mid 80’s cyber security was not much of a major concern outside of tech, many people at the time barely even wanted to have computers in their house because they thought they were “spy machines” or even thought that they were too expensive at the time. Despite this research doing a lot and paving the future for many forms and idea’s of quantum computing and cyber security it still was not one of the easiest things to implement. This issue you ask? Implementing the actual protocol into classical computers. According to the market research firm IDC, the global spending on quantum computing hardware, software, and services is projected to reach $6.6 billion in 2023, up from $1.5 billion in 2019. However, this spending is largely driven by research and development efforts, as well as investment in quantum computing infrastructure by government agencies and technology companies. In contrast, traditional (classical) computers are ubiquitous and have been widely used for decades. According to a 2021 report by Statista, there are an estimated 4.78 billion active internet users worldwide, this is the problem here. Sure, the idea of QKD to come in and change the world worked and happened and is still influencing alot, but the problem of using it is the wide variety of traditional computers that still exist. Based on the percentages and amount of people that use quantum computers it does not seem like QKD will be fully implemented into networks as we do not need it right now for standard computers. The implementation and study of QKD despite not being fully used ( if at all ) right now is still used as a primary introduction to quantum science and the world of modern Q-CompSCI ( Quantum Computer Science ). Now this kind of answers our questions that the people would be asking above. Despite quantum computing existing for quite a few decades now, it is still a very very new thing to the world and classical computers have been around for WAY longer and have been the concrete base to most nations across the world! Because of this, the application of Q-CompSCI with cyber security will be a rough one and it will be a very long time until we can see this merge and actually work, however, Q-CompSCI still remains one of the most focused on fields and worked with fields in the cyber space because it is just one of the better things to study. In conclusion, Q-CompSCI will not change but rather inspire the future for many different idea’s and implementations even algorithms into specific programs.

Quantum Cryptology and Mathematics | A base introduction using QKD

Quantum cryptology as previously discussed is one of the most interesting topics to talk about ( to me at least ) and has many different applications. Well, in this section we will go over one of the most popular quantum cryptography implementations as discussed before which is QKD. QKD otherwise known as Quantum Key Distribution is a method of exchanging secret keys between two parties over an insecure channel such as the internet. The internet is known as a channel because a channel is often defined as a way of communicating otherwise known as a medium for transmitting information between two or more parties. In QKD, a channel example would be the internet but the internet can break down into multiple forms of transportation such as cellular networks, WiFi networks, Bluetooth connections, and even physical connections like ethernet cables. QKD takes ideas and principles from quantum mechanics which allows for the creation of unique and unbreakable keys.

  • ID-13.3 → Simple Explanation of How QKD Works : QKD works by using photons to create a key that is unique between the two parties that are communicating data between each other. These photos are sent over a communication channel which can in some cases be represented using an optical fiber. The properties of these photons such as their polarization or phase are measured by the receiver of that photon. This information is then used to create a shared secret key that can be used to encrypt and decrypt messages transferred between the two parties.
  • ID-13.4 → Benefits of QKD : QKD has a few benefits many of them revolving around cyber security and how it can be used to protect data. For example, the most popular situation with representing QKD is the Alice and bob situation. The Alice and Bob scenario is a common cryptographic representation that is represented like so.
  • Alice and Bob scenario → Bob has a letter he wants to send to Alice, bob then puts his message and letter inside a tiny box with a padlock on it where only bob and Alice share the same key to that same box. Because Alice and bob share the same key the middleman or in this case, the mailman and anyone else delivering that mail can not open that box because they do not share the same key. This situation is easy to represent specific algorithms or representations in cryptography similar to QKD because it is easy to understand and follow for those who do not know much about cryptography. This scenario may also be modified and flexed in specific cases to make it more understandable for specific algorithms.

Using the Alice and Bob scenario we can map out the major benefit of QKD which is offering a secure solution to standard cryptographic solutions. Say Alice and Bob want to communicate securely over some insecure channel which can be represented as the internet. To do so they need to share a key that no one else can intercept that they can use to decrypt and encrypt messages or payloads being sent. If an eavesdropped whose name is eve intercepts their communication she can potentially obtain this key and read or decrypt the messages. This is the problem with traditional cryptographic methods such as symmetric key encryption. Cryptographic methods like symmetric key encryption require Alice and Bob to share a key over the insecure channel which means this is pretty vulnerable to interception and can not be fully guaranteed that it is safe. Even an alternative such as public key encryption requires more complex mathematical algorithms which can be intensive and vulnerable to attacks ( the implementation anyway ). The solution to this problem is exactly what QKD is. QKD instead of sharing the secret key directly over the medium of transportation like traditional methods rather make Alice and bob use parts of quantum mechanics to generate and share a secret key by exchanging individual photons as Alice and bob can also detect attempts of eavesdropping and ensure their key remains secret. The general benefit of QKD is that it provides a highly secure way for Alice and Bob to generate and share a secret key even if the channel they are sending data over such as the internet is insecure. To sum up, one of the major things that QKD brings to the cryptographic world is a much more sophisticated base that can be highly resistant to attacks and even if Eve were to eavesdrop then they would be detected.

In general quantum key distribution so far is looking pretty nice right? Oh no, not another explanation…YUP! Thats right, like everything in this for saken world QKD has its downfalls as well. Despite quantum computing still being relatively new and QKD not being around nothing but 40 years ( almost 50 ) it has had some ups and downs and some improvements while also having some downfalls.

Quantum Computer Science | The downfalls of QKD

QKD is a highly mathematically and computationally advanced method of key distribution and it has so many security benefits but there is a major downfall to QKD. To properly implement it on a system you need high-level software that can represent quantum states enough to transfer that data and even then QKD is still vulnerable to side-channel attacks making it have some very strong downfalls. Below you will find a list of definitions and examples of what type of downfalls QKD has.

  • Side-Channel Attacks: A side-channel attack is not necessarily a standard cyber attack as the methods and the type of target change. In a side-channel attack, the attacker is not targeting the software of the system directly but looking for ways to gather information about a system from the outside such as the physical environment where standard attacks such as SQLI take advantage of the software and programs on the device or target itself. In the case of QKD the implementation of QKD in a quantum system would be exploited by being able to view or collect information on the photons being used. For more information photons in a quantum system are used to transmit data. If an attacker can observe or intercept these photons they can potentially gain information about the key being exchanged. Side channel attacks are also one of the harder attacks to prevent and very hard to detect upon execution.
  • Implementation: QKD can be implemented in so many ways there is even a full set of designs and ways you can go around working with QKD and representing it however the actual implementation and usage of QKD is a bit tasking as it requires specific hardware and software to run it. For example, there are many libraries out there such as Quiskit written by IBM that allows you to virtualize quantum circuits which allows you to represent specific systems like QKD however it is still very well a pain to do so and the actual use case of QKD will be extremely hard to work with as it is a very complex way of transferring cryptographic keys.
  • → Data loss: Quantum computers use photons to transport data and while this makes it lightning fast it also has its downfalls. When it comes down to QKD the environment matters most as QKD depends on photons to transport data. Many fields can change the data, for example, the distance over which it can be used is limited by the loss of photons as they travel through the communication channel. Even environmental factors such as temperature and pressure can affect these performances of QKD.

There are many other issues with QKD despite it being decently secure however this does not mean it is the worst protocol out there, it can still be implemented and still be worked on despite having issues being used within the current state of today’s standard home computers. As said above you can easily represent it but it is the actual use case that becomes very tedious. QKD can still be used and represented which is the point of this as we will represent the situation in Go but not fully implement everything. Currently, the principle of QKD is good to know for future testing and cryptographic studies which is why it is included here.

Quantum Computer Science | How does QKD work computationally?

This section will be explaining a decent step-by-step representation of how QKD works outside of the base explanation. This section will split into 6 individual steps which will explain the different steps of QKD and the process in which it works.

  • Step 1 → Key Generation: Before the communication of the channel starts the two senders and receivers must first generate a key used to encrypt and decrypt their messages.
  • Step 2 → Quantum Transmission: The next step after the key has been generated is to then transmit data over the communication channel such as an optical fiber. The photons that are sent from the sender to the receiver will be sent one at a time through the communication channel. The photons that are sent are also polarized in different directions and it is important to note that when these photons are polarized and sent that the polarization property is a quantum property and any attempt to measure it will disturb the photon.
  • Step 3 → Quantum Measurement: Once the receiver receives the sent photons and data from the sender through the communication channel the polarizations of the photons much be measured, This measurement is a random process and can not be predicted.
  • Step 4 → Public Communication: Once the receiver calculates the photons they were sent then the sender will also communicate the polarizations that they sent
  • Step 5 → Key reconciliation: Once the sender and receiver are done measuring their sets of data and sending them back to each other they then compare their sets and measurement results to identify any issues or discrepancies that happened during transport. If errors happened they will use error correction techniques to reconcile the differences and obtain a shared key. The goal of this step is to ensure that both the sender and the receiver have the same key without revealing it to an eavesdropper.
  • Step 6 → Privacy Amplification: Once the sender and the receiver have obtained a shared secret key they then use a process known as privacy amplification to remove any remaining information that can be used by the eavesdropped to decipher the encrypted data. This method and step involve applying a one-way function to the key which will irreversibly reduce its length and removes any correlations between its bits.

These steps are much deeper than what was explained and could be written in a million different ways, however, this is a general idea and scope of what QKD is and how it’s used, and how it works on a deeper level. Understanding how these works allow us to get a deeper understanding of the source code that we are about to develop representing and making an example of QKD. Before we can go onto developing a base implementation ( without Quiskit ) we will be talking about the protocols that are used along side of QKD.

Quantum Computer Science | Standard protocols

Ever since Charles Bennett and Gilles Brassard proposed the idea of QKD, there has been a TON of research thrown into the field of quantum mechanics and quantum cryptology. With this research, there were issues that came along the line of this or that was found and one of those major issues was the idea of QKD. The idea of QKD is tio establish a shared secret key between two given parties which as talked about before is known as Alice and Bob which can be used for secure communication over a public and unsafe channel like the internet. However, there needs to be a process behind generating and distributing the key between both parties and the distribution would be vulnerable to attacks by an ease dropper ( known as Eve ) who can intercept the information and manipulate it before it reaches either Alice or Bob. To do this and to mitigate this threat comes the birth of protocols which following QKD define a set of procedures and rules that Alice and Bob must follow to ensure the security of the key exchange process. Charles Bennett and Gilles Brassard proposed a protocol along with the idea of QKD which is known as BB84 or otherwise known as the Bennett-Brassard 1984 protocol. The BB84 protocol is one of the very first protocols to exist within QKD and is often used to represent standard QKD and implementations of QKD. Below I have provided a base text and sample which is talking about how QKD works. When we finish talking about the other protocols we will deep dive into the mathematics of QKD.

In QKD, Alice sends a series of quantum states to Bob, each representing a bit of information (0 or 1). These quantum states are usually encoded in individual photons, and the polarization of each photon represents the bit value. However, due to the principles of quantum mechanics, an eavesdropper, known as Eve, cannot observe or measure the quantum states without disturbing them, causing errors that can be detected by Alice and Bob. Alice and Bob then perform a series of measurements on the received photons, and share their results over a public channel. Using classical error-correction codes, they can identify and correct any errors introduced by the transmission and measurement process, and obtain a final key that is known only to them. Since the process of generating and distributing the key is based on the laws of physics, it is theoretically impossible for Eve to obtain a copy of the key without being detected. In other words, QKD provides unconditional security, meaning that the security of the key distribution process does not rely on assumptions about the computational power of Eve or the security of the communication channel.

Despite this cool little explanation on how QKD is good and our little talk above about how good QKD can be if implemented properly, like the list above it still has some limitations. One of the major limitation right now is mainly due to technical issues such as imperfect photon sources, detector inefficiencies and noise in the communication channel, all of which can affect QKD rapidly (recall talking about interruptions in measurements ). Because of this QKD is typically used in some form of hybrid cryptography which means it is used in combination with classical cryptographic techniques to provide stronger security. Protocols are also the reason to shape and help better design protection methods against current cryptographic methods such as RSA. A good example from angelina tsuboi’s article “Quantum Circuits & Key Distribution for Cryptography” represents this using a vulnerability in RSA.

Vulnerability Example: RSA

The RSA (aka Rivest–Shamir–Adleman) cryptographic algorithm is a widely used protocol to secure communication over public channels. However, quantum computers introduced an inherent vulnerability in the algorithm which was that it depended on the inefficiency of classical computing systems to factor large numbers. In response to this vulnerability, security researchers have developed multiple quantum-resistant algorithms such as Quantum-Safe RSA (aka QS-RSA). QS-RSA is a modified version of RSA that uses an alternative quantum-safe mathematical function to generate public and private keys while retaining the traditional RSA encryption/decryption functionalities.

In general, along with BB84 many other protocols have come about and popped up to better address issues in modern cryptography. After all, the whole idea of QKD is to address issues in standard cryptography. Now while the BB84 protocol is widely used, generally speaking BB84 will not always be used because the protocol being used usually depends again on a specific situation or application of the protocol. I have listed an example of where the BB84 in QKD would be used and where it would not be used below.

  • Where BB84 would be used → BB84 is a protocol that was used to secure communication between two parties over a public channel, again such as the internet. The security of the communication is guaranteed by the laws of quantum mechanics which can ensure ( despite the side channel attacks ) that any attempt to intercept or measure the photons used in the protocol would be detected.
  • Where BB84 would NOT be used → In the case that a channel is too noisy or subjected to interference which can cause errors in transmission or quantum states. In such cases, error corrections may need to be employed which can reduce the efficiency and security of the protocol. One protocol that can fix this is Continuous-Variable Quantum Key Distribution (CV-QKD) protocol, which uses continuous quantum variables, such as the amplitude and phase of a coherent state, to encode information instead of discrete qubits used in BB84. CV-QKD is less sensitive to errors caused by channel noise and interference, making it a suitable alternative in such situations.

This is where and why other protocols have been developed, because like standard crypotgraphy, each one has its own ups and downs and with those downs and with those researchers come much more smarter and inteligent people that can address those issues within those algorithms. Below I have provided a list of algorithms that exist within QKD.

  • E91 → Otherwise known as Ekert91 was a protocol proposed by Artur Ekert in 1991, which uses entangled pairs of particles (usually photons) to generate a shared key. It relies on the violation of Bell’s inequalities to detect any eavesdropping attempts.
  • B92 → Otherwise known as Bennett 1992 was proposed by Charles Bennett in 1992, the B92 protocol uses only one basis (rectilinear) to encode information onto qubits. It is simpler than BB84, but also less secure.
  • SARG04 → The SARG04 protocol which was proposed by Stefano Pirandola, Stefano Mancini, and Seth Lloyd in 2004, is a protocol that was designed to be more efficient and practical than previous QKD protocols. It uses a simplified encoding scheme and a novel error correction protocol to increase the rate at which keys can be generated.
  • DPS → The DPS (differential phase shift) protocol and the six-state protocol are two different approaches to quantum key distribution (QKD), which aim to securely distribute cryptographic keys between two parties over a communication channel. The DPS protocol is a continuous variable protocol that uses a phase shift modulation scheme to encode the quantum information. In the DPS protocol, the sender prepares coherent states of light with different phases, and the receiver measures the relative phase shift between the states to extract the key. The DPS protocol is less sensitive to channel noise than some other discrete variable protocols, but it requires more complex hardware to implement.
  • SSP → Also known as the Six-State Protocol (BB84) is a variation of the BB84 protocol with a slight twist if you will. The SSP protocol was designed to be much more efficient with data transmission than the BB84 protocol was. If you know networking protocols, you can follow this concept up with TCP and UDP and why each one works for specific scenarios. The higher rate or rather efficiency was achieved by using three non-orthogonal(two states are said to be orthogonal if they are perpendicular to each other in the state space. This means that if a quantum system is in one state, it is impossible to measure it and find it in the other state. Non-orthogonal states are those that are not perpendicular to each other. This means that there is a non-zero probability that a measurement will find the system in the other state.) quantum states instead of two to encode each bit of the message. The SSP protocol is much more efficient and more or less a modification of the BB84 protocol. Some people will get confused and say they are the same, while being closely related one is much more efficient than the other.

As you can see based on the descriptions of each protocol, you can see that BB84 was despite being the first not the most accurate and stable protocol to its day and that depending on the situation there will be many different applications of these protocols all which depend on the leaning definition. For the scope of this article we will not work with SSP, SARG, E91, B92, or any other QKD related protocol other than BB84. We are using and sticking to BB84 because of the most commonly used introduction to QKD and it will be pretty easy to represent in something like Go. Our next section we will dissect the mathematics of the BB84 protocol and go deeper into how it works on a quantum computer or quantum circuit as a better way to put it.

Quantum Computer Science | The inner workings of BB84

Now we have already gone into depth enough right? HA! No. Anything typically quantum in itself goes extremely deep and into detail and when it comes to Q-CompSCI it gets even deeper. Now, we do not have enough ability for input on medium to go into the deepest levels of quantum mathematics especially when it comes to QKD because you have to have background experience with math, but we can break it down and BARELY touch the tip of the ice burg. Most of my articles even if they are cyber security related all talk about mathematics at some point, whether its an exploit concept, cheat concept, design implementation, AI and ML research or general programming and language development so it is only fair that we give this article a taste of mathematics.

Note: The mathematics and topics described in this section are a bit wild in themselves and BB84 in itself uses multiple algorithms and mathematical concepts in order to complete and implement its rule sets into a quantum circuit. I always tell people to never get discouraged when learning something like this. Quantum mathematics in itself is hard for people to chomp down, but if you never actually dig into something new and as scary as the quantum world can be, you will never truly learn anything new. I encourage you to at least attempt to read and understand this section and I do truly hope that you come out of this section learning something truly impressive and immersive. I have personally found that when working with QKD or really anything in the quantum world, oftentimes it can be confusing and the research into this article took quite literally weeks to actually finish to a point of too many markers being used up, literally. I even found that my brain cells needed a break, so do not panic if you do not understand something because THAT IS LEARNING, you fail and get back up and try again and keep doing that even when you feel weak. Keep going, keep learning and again I heavily encourage you to actually read and not shy away from this section even if you do not get math well, hopefully, I can change your outlook on math after this. It may also be worth noting that not every step is fully mathematical, of course they take some form of mathematics but not every single step requires a deep dive since it is mostly just base logic.

Before we can dig deep into even the slightest forms of mathematics and really work with what we have and know right now we need to understand the process that BB84 takes on its own and instead of the algorithms rather the mathematical steps it takes. Understanding these steps can give us a good base to the math behind BB84.

  • Step 1 → Encoding the Bits: Encoding the bits is a very important process as the sender will generate a random bit string and encode each bit as a Qubit using one of four possible basis states. An example of this is where the sender could encode 0 as either a 0 in the standard basis or a + in the Hadamard basis, and a “1” as either a “1” in the standard basis or a “-” in the Hadamard basis.
  • Step 2 → Sending the bits: This step is the actual transportation of the bits and requires that the sender will send the bits over a quantum channel to a reciver or destination.
  • Step 3 → Choosing the measurement basis: The receiver or destination will also generate a random bit string and chooses a measurement basis for each bit the receiver receives. The receiver can then either measure the qubit in the standard basis (0or 1) or the Hadamard basis (+ or -). The receiver then records its measurement basis choice for each qubit, but does not reveal his actual measurement outcome to Alice.
  • Step 4 → Measuring the qubits: The receiver measures each qubit in the chosen measurement basis. Because of the uncertainty principle in quantum mechanics, Bob’s measurement disturbs the state of the qubit, so he can’t send the qubits back to Alice.
  • Step 5 → Discarding / Verifying incompatible measurements: When everything gets past the 4th step both the receiver and sender measure their basis choices for each cubit and compare them. If they used the same basis, the receiver's measurement result corresponds to the senders encoded bit. If they use different bases the measurement result is random and uncorrelated the senders bit and will discard these uncorrelated measurements.
  • Step 6 → Error correction: The sender and the receiver publicly announce the indices of the remaining qubits for which they used the same measurement basis. They compare the measurement results for these qubits and check if there are any discrepancies. If there are discrepancies, it indicates that there may have been errors in the transmission. Both the sender and the receiver will use classical error correction techniques to correct any errors.
  • Step 7 → Privacy amplification: To ensure that their key is secure even if an eavesdropper has intercepted and measured some of the qubits, the sender and receiver perform privacy amplification. They use a hashing function to compress the remaining bits into a shorter, but more secure, key.

These are some wild steps right? Well, in order for each task to work they need to work with some form of algorithm or mathematical equation to implement these factors and push them into reality and to follow the rule sets. The next bullet point list will break down each step and each of its expressions or algorithms that they use ( step 5 is skipped due to there not really being a full form of algorithm or set state or name used for it other than verification ).

  • Step 1 → Quantum State Preparation (QSP): In the quantum state preparation the sender will prepare a set of quantum states to send to the receiver. These states can be polarized photons, a good example is that the sender will randomly choose from a set of possible state’s and send them to the receiver over a quantum channel. The state of each qubit can be represented by a 2D vector in a complex vector space such as.
|0⟩ = [1, 0]
|1⟩ = [0, 1]
  • Step 2 → Basis Selection: In this secondary step, the sender and the reciever will both randomly choose the basis in which they will measure the specified Quantum Bits (QuBits). The basis can be two different kind which are listed below.

Standard: The standard basis which looks like |0⟩ and |1⟩ can be used and is more likely to be used.

Hadamard basis: The Hadamard basis is represented by |+⟩ and |-⟩.

The choice of the basis typically is determined using a random number generator or a pseudo random sequence generator.

  • Step 3 → Randomness: Randomness especially when it comes to the BB84 protocol is quite important. In this step, the sender and the receiver generate random bit strings to determine the measurement basis for each qubit. Randomness ensured that the selection of measurement basis is completely unpredictable and also helps with the security of the used protocol and in our case is BB84. This can be achieved using methods such as hardware-based random number generators or other cryptographic algorithms.
  • Step 4 → Quantum Measurement (QM): In this step, the receiver will perform a measurement on the qubits the sender sent to the receiver. The measurements can be measured using either the standard or Hadamar dbasis similar to the basis selection. The outcome of the measurement also determines the classical bit value associated with each qubit. The measurement process will follow the principals of quantum mechanics including superposition and collapse of wave functions.
  • Step 6→ Error Correction: Error correction is another extremely important step when using or implementing the BB84 protocol. This step allows the sender and receiver to correct any errors that may have occurred during transmission. Classical error correction techniques such as the binary repetition code or the hamming code can be applied to identify and correct errors. During this step, both the sender and the receiver will compare the measurement results for specific qubits that were prepared and measured in the same basis Discrepancies in the measurement outcomes indicate potential errors that can be corrected using very specific error correction codes.
  • Step 7→ Privacy amplification: Privacy amplification is a step that is used to enhance the security of the shared key even in the presence of a potential eavesdropper. This step works by compressing the remaining bits into a shorter, more secure key using a cryptographic hashing function. The hashing function that is used takes the measured values and other parameters as input then finally produces a secure key with reduced information about the original qubits.

BB84 as a protocol is extremely complex and complicated even with a base understanding it can be quite hard to understand the more mathematical side of things. In the next section under this primary section we will be understanding a basic detail of the Hadamard basis which will be quite confusing for some people but I will try to keep it as basic as possible.

Quantum Mathematics and Cryptology | Basis and Hadamard

For the base understanding, the hadamard basis is a mathematical concept that is used primarily within information theory and quantum computing.c This specific basis plays a major role within the BB84 protocol due to its properties and benefits that make it quite suitable for quantum key distribution. The name hadamard comes from a french mathematician by the name of Jacques Hadamard who has an extremely rich background in both mathematics and physics. Hadamard was also known for how tight and extremely large his contributions were to various fields of mathematics including number theory, analysis, and algebra. During the late 1900’s ( 1893 ), Hadamard published a groundbreaking paper on the determinant of a matrix known as Résolution d’une question relative aux déterminants (Resolution of a question concerning determinants [ English Translation ] ) which laid the foundation for the theory of linear transformation in matrix algebra. Now lets talk for a second, how can someone like hadamard contribute so much to a field that did not even exist? The thing is that Hadamard himself did not create the gate or the logic behind it but rather laid a foundation for future developers. The concept of hadamard’s basis in quantum computing and information theory merged much later during the mid-20th century that the Hadamard gate and its associated basis gained prominence in the field of quantum mechanics. The hadamard gate was introduced in 1959 by a physicist and mathematician by the name of Leonard Schiff. Jacques Hadamard himself did not specifically introduce the Hadamard gate in his works but rather the term “Hadamard gate” was coined later in honor of his contributions to mathematics, particularly his work on matrices and determinants. This gate which is typically referred to as the H gate is a fundamental quantum get used in quantum computing and quantum information theory. This gate operates on a single quantum bit (qubit) and transforms it from the standard basis (|0⟩ and |1⟩) to the Hadamard basis ( |+⟩ and |-⟩ ) and vice versa. The gate is defined by a specific matrix representation known as the Hadamard matrix. Now, while Hadamard’s original work focused on various branches of mathematics, his influence extended to quantum computing through the recognition of his contributions to matrix theory. This kind of answers our question. Quantum computing like standard computing in itself is a whole different field, but there were people centuries before that were the building blocks to quantum computing and mathematicians that were able to spark idea’s in other’s minds based on their own research contributing to mathematical fields.

Quantum Mathematics and Cryptology | Standard vs Hadamard

In this section before we go into explaining the basic’s of the math or setting up a situation to mathematically explain hadamard, we must first understand the prime differences between the two. This section creates a tree of bullet points comparing the two.

Standard Computation Basis ( |0⟩ and |1⟩ )

  • The computational basis states represent the classical binary states of a quantum bit. The state |0⟩ corresponds to the definite and deterministic classical bit value of 0, while the state |1⟩ will correspond to the definite and deterministic classical bit value of 1. The name classical refers to the standard classical bit system used by regular computers ( non quantum based computers ). These states are mutually exclusive and non-overlapping. If a quantum bit is prepared in the state of |0⟩, it will collapse to the measurement outcome of 0 with certainty. Similarly, if its prepared in the state of |1⟩ it will collapse to the measurement outcome of 0 with certainty. In terms of the measurement probabilities for standard computation basis, the probabilities of measuring the computational basis states will always be 1 and 0 respectively.

Hadamard Basis States ( |-⟩ and |+⟩ )

  • The Hadamard basis is much more complex and a bit more different in representing its states than the standard computation basis. In terms of the hadamard basis, instead of representing the states as classical binary states of a quantum bit, it rather represents it as quantum superposition states. These states are formed by applying the Hadamard gate to the computational basis states. Similar to the standard computation basis, instead of using 0 and 1 the Hadamard basis uses ( |-⟩ and |+⟩ ) which works as follows.
  • → |+⟩ Representation (plus state) : This represents a superposition of |0⟩ and |1⟩. This is known to be an equal superposition of both states meaning there is a 50% chance of measuring it as 0 and a 50% chance of measuring it as 1.
  • → |-⟩ Representation ( minus state ) : Similar to |+⟩, the minus state represents a super position |0⟩ and |1⟩, but with a phase difference of PI compared to |+⟩. This phase difference results in a relative negative sign when measuring the minus state ( |-⟩ ) and the plus state ( |+⟩ ). The Hadamard basis states are known to be orthogonal to each other which in this context means or refers to a specific relationship between the quantum states. Basically its when two quantum states are said to be orthogonal if their inner product or dot product is zero. In the case of the computational basis states and the hadamard basis states they are considered to be orthogonal together because the inner product of any computational basis state with any Hadamard basis state is zero. Mathematically speaking, this can be expressed as
⟨0|+⟩ = ⟨1|+⟩ = ⟨0|-⟩ = ⟨1|-⟩ = 0

Concluding the representation of the minus state, the fact that they are orthogonal to each other means that if you measure a quantum bit prepared in the |+⟩ (plus) state it will collapse to either |0⟩ or |1⟩ with equal probability. When measuring a quantum bit in the |-⟩ (minus) state, like the plus state, it will collapse to either |0⟩ or |1⟩ states with equal probability but with a relative negative symbol.

To conclude this section, the major difference between the two sets of states lies in the super-positional properties. The computational or standard basis states are definite and represented as classical bits where the hadamard basis states are superposition that allow for quantum phenomena like inference and parallel computation. The Hadamard gate facilitates the transformation between these two basis in turn allowing the creation and manipulation of quantum superposition states in quantum algorithms and protocols like BB84. But why exactly is the Hadamard gate and the associated basis commonly used in QKD? There are many prime reasons which all fall under 4 main points.

  • Generation of Superposition States: The Hadamard gate allows for the creation of superposition states by transforming the given computational and classical basis states of both 0 and 1 into the hadamard basis states which were shown below as the plus and minus state ( |+⟩ and |-⟩ ). In quantum computing, superposition states are essential because they enable the transmission of quantum information that is simultaneously in multiple states. This property allows for much more greater efficiency and capacity in the transformation of quantum bits. This is a benefit for use cases like BB84 because it allows for the transmission of quantum information that is simultaneously in multiple states as stated before. In the BB84 protocol, the sender needs to encode the bits as quantum bits using either the computational basis or the Hadamard basis as also talked about before. By utilizing or choosing the Hadamard gate to transform the computational basis into the hadamard basis, the sender can send quantum bits in a superposition of states. This can enhance the efficiency and capacity of the transmission.
  • Enhanced Security: QKD protocols aim to establish secure communication channels by leveraging the principals of quantum mechanics, because without quantum mechanics or principals of quantum mechanics, QKD protocols could not fully secure transmission. The use of the Hadamard basis in QKD introduces much more security measures than standard basis. By randomly encoding quantum bits in either the computational basis or the hadamard basis, the sender and receiver introduce a level of randomness and uncertainty that enhances the security of the key exchange over the unsecured channel. The hadamard basis allows for the generation of random and uncorrelated measurement outcomes which can make it much more difficult for an eavesdropper to intercept and gain information about the transmitted key over the channel. This is a major benefit because of how difficult it can be for an eavesdropper to intercept and gain information about the transmitted key.
  • Error Detection and Correction: When it comes down to choosing the basis, the Hadamard basis can over step and over rule the standard basis through its crucial role in error detection and corrections especially in BB84. During the correction phase, as we mentioned before both the sender and receiver compare their measurement outcomes for the qubits measured in the same basis. By using the Hadamard basis, the protocol can detect errors much more efficiently since errors will typically manifest as discrepancies in measurement outcomes between the sender and the receiver. The benefit of this is to enable the identification and correction of errors which can ensure the accuracy and reliability of the final key.
  • Versatility and Adaptability: Given that the Hadamard gate and basis are versatile tools in quantum computing and information processing, they can be combined with other quantum gates and operations to perform a wide range or quantum algorithms and protocols. The Hadamard gate, in particular, is usually used in various quantum algorithms most of which seem to be used within QKD. This is because of its ability to create superposition states and facilitate transformations between bases makes it a valuable component. The Hadamard gate would benefit BB84 when it comes to encoding the quantum bits in the Hadamard basis which allows or enables the subsequent steps of the protocol. Because of its versatility, the Hadamard gate allows for its integration of other quantum cryptographic schemes as well which is another prime benefit.

To conclude this section, the basis and the gates all may achieve the same exact thing but do it differently, and the execution and process as well as implementation may weigh out the pros of another gate or basis and in this case the Hadamard gate might be a better choice for the sender and receiver to use. Now lets move onto the mathematical base situation. We will not go deep into this but it is a good thing to go over to say the least.

Quantum Mathematics and Cryptology | Basic mathematical setup [Hadamard]

The Hadamard gate as we have discussed is a quantum gate that operates on a single quantum bit and will transform it from the computational basis to the Hadamard basis.Lets mathematically define and explain this given transformation. To start off with, the Hadamard gate is represented by the following matrix.

H = (1/√2) * [[1, 1], [1, -1]]

This is used to represent the gate because it captures the specific transformation that the gate applies to the computational basis ( ( |0⟩ and |1⟩ ). So lets go a bit deeper into this here and pick apart this matrix. Before we go into the different factors lets break down the actual matrix itself. The reason we do so is to make sure that when we mention bottom left, top left, bottom right and top right elements we know what we are talking about.

We can visualize the matrix as the following

[
[1, 1], // Top | top left, top right
[1, -1], // Bottom | bottom left, bottom right
]
  • Top Left Element: The top left of the element is the scaling factor applied to the element located in the top-left position of the matrix which is 1 → (1/√2).
  • Top Right Element: The top right element represents the scaling factor applied to the element located in the top right POS ( Position ) of the matrix which here is also 1 → (1/√2).
  • Bottom Left Element: The bottom left element represents the scaling factor applied to the element located in the bottom left position of the matrix which again is also 1 here → (1/√2).
  • Bottom Right Element: The bottom right element of the matrix represents the scaling factor applied to the element located in the bottom right position of the matrix which is -1 → (-1/√2).

Now we can break down the matrix itself.

  • Normalization Factor: The factor of (1/√2) in front of the matrix ensures that the resulting states have the appropriate normalization. This is necessary to maintain the probabilistic interpretation of the given quantum states where the squared amplitudes represent probabilities.
  • Basis transformation: The Hadamard gate transforms the computation basis states into the Hadamard basis which again was represented above. The matrix elements all represent the amplitudes of the resulting states after the transformation! The element in the top left position, 1/√2 corresponds to the amplitude of |+⟩ resulting from the transformation of |0⟩. This indicates that the state |0⟩ has a 1/sqrt(2) probability of becoming |+⟩ states. The element in the top right position represents the amplitude of |+⟩ resulting from the transformation of |1⟩. This indicated that the state |1⟩ also has a 1√2 probability of becoming |+⟩. The element in the bottom left position, 1√2, corresponds to the amplitude of |-⟩ resulting from the transformation of |0⟩. This indicates that the state |0⟩ has a 1/SQRT(2) probability of becoming |-⟩. Now the bottom right element in the position of -1/SQRT(2) represents the amplitude of |-⟩ resulting from the transformation of |1⟩. This indicates that the state of |1⟩ has a -1/SQRT(2) probability of becoming |-⟩
  • Orthogonality and Superposition: The Hadamard gate also transforms the orthogonal computational basis states into superposition states. The resulting states of plus and minus states are orthogonal to each other and will form a new basis that is equally spaced in the block sphere. The plus and minus states are orthogonal because their inner product is zero, as can be verified by calculating their dot product which is as follows.
⟨+|−⟩ = (1/√2) * (1/√2) * (1 + -1) = 0

The plus and minus states are superposition states because they cannot be expressed as a single computational basis state. They represent a coherent combination of both |0⟩ and |1⟩, with equal amplitudes. By using the matrix representation, the Hadamard gate can be easily applied to quantum states and used in quantum, algorithms and protocols like the BB84 protocol in our case. Now in order to understand the transformation happening, lets consider the action of the Hadamard gate on the computational basis states such as the following.

H(|0⟩) = (1/√2) * [[1, 1],
[1, -1]] * [[1], [0]]
= (1/√2) * [[1], [1]]
= (1/√2) * (|0⟩ + |1⟩) = |+⟩
H(|1⟩) = (1/√2) * [[1, 1],
[1, -1]] * [[0],[1]]
= (1/√2) * [[1], [-1]]
= (1/√2) * (|0⟩ - |1⟩) = |-⟩

So given our transformation, applying the Hadamard gate to the computational basis states transforms the |0⟩ to |+⟩ and |1⟩ to |-⟩. Geometrically, this transformation corresponds to a rotation of the quantum bits state by 90 degrees around the vertical axis of the Bloch sphere which looks like the image below.

Bloch sphere example NOT DIRECT TO EQUATION

Now, the Hadamard basis states that |+⟩ and |-⟩ are superposition of the computational basis states, representing a state with equal probabilities of being measured as 0 or 1. The transformation provided by the Hadamard gate is a key operation in quantum algorithms because it allows for the creation of superposition state and enables quantum interference and parallelism in computational tasks or executions.

We were able to decently break down what was happening but something to learn from this section is that I may not have gone as deep because readers would then require an insane amount of knowledge in linear algebra and quantum mechanics to understand quantum mathematics and breaking down specific algorithms. We can also finally move onto our next section.

Quantum Cryptology | Using Golang for QKD Demo’s

This section is much more different, instead of going over QKD we will break this down into how to demo and represent QKD using the Go programming language. We have the slightest and most minimal knowledge to be able to also understand how to represent QKD. It is important to note that quantum computers operate 1 million times differently than regular computers and have a whole new concept. In order to fully represent and see how QKD works we would need specific software or libraries that were built for that such as Python’s Qiskit library developed by IBM. This library can help us build programs that simulate quantum computation and boil it all down to base computer science. Using libraries like Qiskit we can better represent these situations, but remember the goal of this article is to represent the idea instead of directly inspecting its activity and how it works directly.

Designing the demonstration and code base

This section will be small but we will go over the base introduction and base build for implementing this idea of Alice and bob. The idea of our program is not going to be designed over a shared network or will be represented using the internet as for this implementation it would be good to just give you an understanding of how to implement QKD in a non-quantum environment. Currently, there is no Quiskit library for golang so we have to do this raw and represent structures that represent a qubit and then manually measure the polarization. Below this text, you will find a general outline of how this program will work.

  • The protocol choice: To work with implementing QKD we need to choose a protocol. Many protocols can work with the implementation of QKD such as the E92, B92, and SARG04 protocol but for this implementation, we will be using BB84. The BB84 protocol was a protocol invented by Charles Bennett and Gilles Brassart in 1984 which was designed to allow two parties such as Alice and Bob to establish a secret key over an insecure communication channel without the need for a pre-existing secret key or assumptions about the computational power of an eavesdropper which in our case is known as Eve.
  • Structure Representation: To ensure that our data is kept clean and can be accessed we will be using structures to keep track of this data. We will make two structures known as QuantumBit which will keep track of the polarization and the value of the quantum bit ( Qubit ) where the polarization is the polarization of the photon being represented. Then we will make a QuantumResults structure which will store the results of the shared bits between the two parties (Alice and Bob ) and the bits between Alice and Bob.
  • Starting functions: We will create a function called init which will run before main to call rand.seed which will seed a random number generator with the current time so that the random numbers generated within the program or by the program are truly random.
  • Quantum Measurement Function: We also need a function that will define the quantum measurement step which will use our structure QuantumBit to store measurements of the polarization's of the given Qubit. This function will take an argument where the argument is the polarization basis used to measure the Qubit. If the polarization is equal to the qubits polarization the method returns the qubit’s value and if not it will return a random bit using the rand.Intin which will be either 0 or 1 or a random integer between the two.
  • Setup Functions: Our setup functions will be the functions we will need to lay out for each party such as Bob and Alice or vice versa. The first person to generate the key in the original Alice and bob scenario will be Alice because Alice will generate a sequence of Qubits where each Qubit is consisting of a randomly chosen polarization and value then for each qubit a random base is chosen and the resulting qubit is then measured using that basis. The same works for bob except bob will not generate the key, bobs setup function will only measure each of the same qubits using his own randomly chosen basis and the measurement results are then stored.
  • Final Call Functions: We will then design the final call function which will measure and compare the bits to see which ones were measured using the same basis which those same bits are then used to create the shared key which is the result of the QKD process.

Below you will find the full source code for this implementation along with an example idea of what is happening.

Quantum Cryptology | The source code to Implementation

package main


import (
"fmt"
"math/rand"
"time"
)


const (
BIT_0 = iota
BIT_1 = iota
)


type QuantumBit struct {
Polarization int
ValueOfBit int
}


type QuantumResult struct {
AliceBitCounts []int
AliceBaseCount []int
BobBItCount []int
BobBaseCount []int
SharedBits []int
}


var (
QBIT QuantumBit // Quantum bit
QRES QuantumResult // Result of the calculations and data
Qubit = make([]*QuantumBit, 16)
SharedQubit = make([]int, 0)
Alices_Bits = make([]int, 16)
Alices_Bases = make([]int, 16)
Bobs_Bits = make([]int, 16)
Bobs_Bases = make([]int, 16)
)


func init() {
rand.Seed(time.Now().UnixNano())
}


func (Qubit *QuantumBit) Step_3_MeasurePolarization(pol int) int {
if pol == Qubit.Polarization {
return Qubit.ValueOfBit
} else {
return rand.Intn(2)
}
}


func Setup_Call_Alice() {
// Alice = sender
// Generate a sequence of bits | Alice setup function |
// Generating the key
for i := 0; i < 16; i++ {
polarization := rand.Intn(2)
value := rand.Intn(2)
Qubit[i] = &QuantumBit{
polarization,
value,
}
}
// Generate random basis for each qubit and measure it | Alice setup function |
for idx, qubit := range Qubit {
basis := rand.Intn(2)
Alices_Bases[idx] = basis
Alices_Bits[idx] = qubit.Step_3_MeasurePolarization(basis)
}
QRES.AliceBaseCount = Alices_Bases
QRES.AliceBitCounts = Alices_Bits
}


func Setup_Call_Bob() {
//Bob randomly chooses a basis for each qubit and measures it
//Bob = Reciever
for idx, qubit := range Qubit {
basis := rand.Intn(2)
Bobs_Bases[idx] = basis
Bobs_Bits[idx] = qubit.Step_3_MeasurePolarization(basis)
}
QRES.BobBItCount = Bobs_Bits
QRES.BobBaseCount = Bobs_Bases
}


func FinalCallCheckAndVerifyBits() {
for i := 0; i < 16; i++ {
if Alices_Bases[i] == Bobs_Bases[i] {
fmt.Println("[+]-[QSTAT]-[+] => Found equal bit...")
SharedQubit = append(SharedQubit, Alices_Bits[i])
}
}
QRES.SharedBits = SharedQubit
}


func main() {
Setup_Call_Alice()
Setup_Call_Bob()
FinalCallCheckAndVerifyBits()
fmt.Println("Alice's bits:", QRES.AliceBitCounts)
fmt.Println("Alice's bases:", QRES.AliceBaseCount)
fmt.Println("Bob's bits:", QRES.BobBItCount)
fmt.Println("Bob's bases:", QRES.BobBaseCount)
fmt.Println("Shared bits:", QRES.SharedBits)
}

Before we move onto running the application lets actually dissect what is happening here and lets walk through the setup a little bit. Below I have cut this code up into multiple subsections.

Source Code Break | The top level (Constants)

The top level of a program is where packages are imported, modules are declared, constants and even type structures remain. In our top level of the program we first ( after imports ) define a constant list shown below.

const (
BIT_0 = iota
BIT_1 = iota
)

This constant list defines both 1 and 0 binary bits. This will be used in our program to represent the values 0 and 1 respectively. These constants will serve as convenient labels to represent the two possible states of a classical bit in the context of BB84. Recall that we are doing a base demonstration and are going to use the most known protocol which is BB84 as SARG and other various protocols are much more complex to read into for the scope of this article. The values 0 and 1 correspond to the two orthogonal states of a classical bit where 0 represents the “off” state and the 1 represents the on state ( false and true ). These bits will be used in various steps of the protocol that will allow us to generate keys, compare bases and verifying shared bits.

Source Code Break | The top level (Structures)

In the next part of the code we have some structure definitions which all look like the following.

type QuantumBit struct {
Polarization int
ValueOfBit int
}

type QuantumResult struct {
AliceBitCounts []int
AliceBaseCount []int
BobBItCount []int
BobBaseCount []int
SharedBits []int
}

The first structure QuantumBit will represent the structure of a quantum bit (Qubit) which drops down into two main fields of the following.

  • Struct Quantum Bit | Field Polarization: This field in the structure represents the polarization of the Qubit.
  • Struct Quantum Bit | Field ValueOfBit: This field in the structure represents the binary value ( either 0 or 1 ) of the Qubit.

Then we have our section structure which is called QuantumResult which holds the results of the calculation and data within the protocol. This contains several slice fields of type integer to store the counts and shared bits of the receiver and sender during the protocol’s execution.

Source Code Break | The top level (Variables)

There is a large amount of variables within this code snippet that was shown above so lets break the following list down.

var (
QBIT QuantumBit // Quantum bit
QRES QuantumResult // Result of the calculations and data
Qubit = make([]*QuantumBit, 16)
SharedQubit = make([]int, 0)
Alices_Bits = make([]int, 16)
Alices_Bases = make([]int, 16)
Bobs_Bits = make([]int, 16)
Bobs_Bases = make([]int, 16)
)
  • QBIT: Is a representation for the type QuantumBit to represent a singular quantum bit.
  • QRES: Is a representation for the type QuantumResult to represent the result of the protocol.
  • Qubit: Declares a slice of pointers to QuantumBit to represent an array of quantum bits. The array has a length of 16 to show the total number of quantum bits used within the protocol.
  • SharedQubit: Declares an empty slice of type integer to store the shared bits between the sender and the receiver.
  • Alices_Bits: Declares a slice of type integer to store Alice's measured bit values for each quantum bit.
  • Alices_Bases: Declares a slice of type integer to store Alice’s chosen bases for each quantum bit.
  • Bobs_Bits: Declares a slice of type integer to store bob’s measured values for each quantum bit.
  • Bobs_Bases: Declares a slice of type integer to store bob’s chosen base for each quantum bit.

These all play an important role in storing everything that is happening during the computation or execution of the protocol.

Source Code Break | The top level (Initiation)

The init function is a special function that allows us to seed the randomization number generator seed based on the current time before the function main is run. This allows for the randomization piece.

func init() {
rand.Seed(time.Now().UnixNano())
}

Source Code Break | The mid level (Structure Based Functions)

Within this file we have a function that is tied and labled with the QuantumBit function.

func (Qubit *QuantumBit) Step_3_MeasurePolarization(pol int) int {
if pol == Qubit.Polarization {
return Qubit.ValueOfBit
} else {
return rand.Intn(2)
}
}

This function exists within the code because it represents the measurement step for a quantum bit. It will take an argument or parameter called pol which is the polarization basis and returns the measured value of the quantum bit. If the chosen polarization matches the actual polarization of the quantum bit it will return the value of the quantum bit. if it does NOT match the current polarization, indicating that this was a measurement basis, it will return a random value simulating the randomness introduced by measuring in the wrong basis.

Source Code Break | The mid level ( Base functions )

Within the rest of the program before the main function we need to declare some calculation based functions which are shown in the brick below. Before we show the brick I would like to mention that the code shown here is not just for measurement but also setup functions for Alice and bob ( senders and receivers ) .

func Setup_Call_Alice() {functions
// Alice = sender
// Generate a sequence of bits | Alice setup function |
// Generating the key
for i := 0; i < 16; i++ {
polarization := rand.Intn(2)
value := rand.Intn(2)
Qubit[i] = &QuantumBit{
polarization,
value,
}
}
// Generate random basis for each qubit and measure it | Alice setup function |
for idx, qubit := range Qubit {
basis := rand.Intn(2)
Alices_Bases[idx] = basis
Alices_Bits[idx] = qubit.Step_3_MeasurePolarization(basis)
}
QRES.AliceBaseCount = Alices_Bases
QRES.AliceBitCounts = Alices_Bits
}

func Setup_Call_Bob() {
//Bob randomly chooses a basis for each qubit and measures it
//Bob = Reciever
for idx, qubit := range Qubit {
basis := rand.Intn(2)
Bobs_Bases[idx] = basis
Bobs_Bits[idx] = qubit.Step_3_MeasurePolarization(basis)
}
QRES.BobBItCount = Bobs_Bits
QRES.BobBaseCount = Bobs_Bases
}

func FinalCallCheckAndVerifyBits() {
for i := 0; i < 16; i++ {
if Alices_Bases[i] == Bobs_Bases[i] {
fmt.Println("[+]-[QSTAT]-[+] => Found equal bit...")
SharedQubit = append(SharedQubit, Alices_Bits[i])
}
}
QRES.SharedBits = SharedQubit
}

So lets break down the functions into their own descriptions so we can understand how this code works.

  • Function 1 : Setup_Call_Alice (SETUP FUNCTION) → This function is known as a setup function or a function to represent the setup process for Alice who is the sender in the representation. This function will generate a sequence of 16 Quantum Bits of type (Qubit[]) which is an array of the quantum type representation. For each generated quantum bit, it will also randomly assign a measurement basis and measures the bit value using the function Step_3_MeasurePolarization() then storing the results in the fields and variables declared at the top level of the program for Alice. The program will then update the QRES structure with Alice’s measured bit counts and measurement basis.
  • Function 2: Setup_Call_Bob ( SETUP FUNCTION) → This function is similar to Alice's setup function. In the case of our cryptographic example of Alice and bob and the BB84 protocol, according to the context bob is the receiver. This function will simulate randomly choosing a measurement basis for each qubit (Qubit[]) and then measuring the bit values using the Step_3_MeasurePolarization() function finally storing them in the respected values and variables for bob. The program will then update the QRES structure with bobs measured bit counts and measurement basis.
  • Function 3: Final_Call_Check_AndVerify_Bits ( VERIFICATION ) → This function will be the final called function to finish off the program. This function will perform the final check and verification of the shared bits between Alice and Bob ( sender and receiver ) and then compare the measurement bases of each quantum bit and checks for equality. If the bases are equal for a quantum bit, indicating that both Alice and Bob measured in the same basis, the corresponding value is considered shared and will be appended to the SharedQubit slice. The shared bits are then stored in the quantum result structure named QRES .

Source Code Break | The bottom level ( Main functions )

The main function will be the entry point to our program and will call all of the required functions after the init function is executed and finished its task. The main function looks like the following.

func main() {
Setup_Call_Alice()
Setup_Call_Bob()
FinalCallCheckAndVerifyBits()
fmt.Println("Alice's bits:", QRES.AliceBitCounts)
fmt.Println("Alice's bases:", QRES.AliceBaseCount)
fmt.Println("Bob's bits:", QRES.BobBItCount)
fmt.Println("Bob's bases:", QRES.BobBaseCount)
fmt.Println("Shared bits:", QRES.SharedBits)
}

This function is what it seems like, it will call the functions for the setups of the sender and receiver, then it will call to check and verify the bits and display the information in the screen.

Lets now see what it looks like when we run this program.

Quantum Cryptology| Example Demo && Conclusion

Running the Program

Upon running this program you may get something similar to this.

[+]-[QSTAT]-[+] => Found equal bit…
[+]-[QSTAT]-[+] => Found equal bit…
[+]-[QSTAT]-[+] => Found equal bit…
[+]-[QSTAT]-[+] => Found equal bit…
[+]-[QSTAT]-[+] => Found equal bit…
[+]-[QSTAT]-[+] => Found equal bit…
[+]-[QSTAT]-[+] => Found equal bit…
[+]-[QSTAT]-[+] => Found equal bit…
[+]-[QSTAT]-[+] => Found equal bit…
Alice's bits: [0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0]
Alice's bases: [0 0 1 0 1 1 0 0 0 1 1 1 0 1 1 0]
Bob's bits: [1 1 0 0 0 1 0 1 1 1 1 1 1 1 0 1]
Bob's bases: [1 0 1 0 1 0 0 1 0 0 0 1 1 0 1 0]
Shared bits: [0 0 0 0 0 1 0 1 0]

Upon execution we get a debug output telling us the program found an equal bit which will be thrown into the shared bits list. We then get hit with alices bits and bases which represents the senders bits and bases. The line for alice’s bases shows the bases chosen by alice for each quantum bit. The value 0 will represent the computational basis ( Z-basis ) and 1 which represents the Hadamard basis (X-Basis). The bits shows the bit values obtained by Alice and bOb durin g the measurement process. Each elemement within the array represents the measured bit value for a specific quantum bit. These fields fall the same for bob. The shared bits which is the final output will indicate the shared bits between the sender and the reciever ( alice and bob ). These bits are the result of the measurement bases that matches as indicated by the previous number of messages within QSTAT.

Conclusion & Thank you

This article, was another extremely, long, annoying to get through article, trust me, writing it was not as easy as reading it XD! But we are finished now and congrats on coming this far for the article. This article went quite deep but really surface level into quantum mechanics, quantum cryptology, and quantum mathematics. We first started to talk about how specific protocols work, why protocols exist, quantum systems and then quantum circuites. We then continued onto explain exactly how Hadamard’s basis and gate works and why it may be chosen for the use of BB84. As mentioned before, this article only scratched the basics but we can learn a ton about modern systems and where the world is heading based on the knowledge you may have picked up. Concluding this article I would first like to thank you guys for reading and keeping up with this series of things, it has been a while since I worked on this article and I was happy to finish, I also want to thank Angelina Tsuboi for providing some amazing base research on quantum algorithms that can be used for the base of this article. Finally, quantum computers are not new, the field of quantum mechanics is quite new to the world but old in terms of computers and technology but not as old as standard computing. In fact, the world is just now as of 2023 starting to really get into quantum computing and do real research behind algorithms, computer systems and even running into major use cases. Most of the scientifically companies like IBM have known and done research on quantum computers or quantum fields for decades and already have quantum computers in use. This is a very interesting thing to start seeing as the world goes round and round we may see quantum computing become used much more than it already is. As also noted by our demonstration, while not everyone has direct physical and digital access to quantum computers, we can still write demonstrations of quantum theory or quantum algorithms such as BB84 like we did today. We can even go a step further and actually talk about Qiskit and implementing or simulating quantum circuits in regular computers to examine and test behavior of what specific quantum algorithms or theory may do to the internals of a quantum computer. This is also where we start to decide the limits and what not that will be placed on uses of quantum computing as the benefit's will most likely outweigh the negatives!

If you ( the reader ) would love to support me I have posted some links below in another primary section.

Support and Other Platforms | Socials / Find me

--

--

Totally_Not_A_Haxxer

Cyber Security Educator, Developer, Social media manager, Author, youth education, content creation, engineering, ui/ux, RE