---
title: "Quantum Cryptography"
format:
  html:
    toc: true
    number-sections: true
---
[In-class notes](HandWrittenNotes/CryptographyClass3.pdf)

## Learning Goals

- Predict outcome of simple quantum polarization measurements
- Describe classical secret key protocol
- Understand key terms: encode/encrypt, decode/decrypte, secret key, encoded message
- Describe BB84 quantum cryptography protocol and why it is secure

## Classical Secret Key Protocol and Intro to Quantum Cryptography

The characters:    

- Alice: has a secret message $m\in\{0,1\}^n$ that she wants to sent to Bob (and no one else)
- Bob: wants to receive the message from Alice
- Eve: can hear everything that Alice tries to send to Bob, and they know the protocol.

Classical Secret Key Protocol:

1. Alice and Bob share a secret random key $s\in\{0,1\}^n$
1. Alice creates an encoded message $\bar{m}=s\oplus m$. (This means take each bit of $s$ and add it modulo 2 to the corresponding bit of $m$. Thus $\bar{m}\in\{0,1\}^n$.)
1. Alice sends $\bar{m}$ to Bob. (Eve also receives $\bar{m}.$)
1. Bob decrypts $\bar{m}$ by computing $\bar{m}\oplus s$ resulting in $m.$

On your first problem set, you will look into why this is secure against Eve, even though Eve knows the protocol and can listen in on communication. (They only are ignorant about $m$ and $s$.)

**Problem:** How to share the secret key?!  
**Current solution:** Public Key Cryptography  
**Looming problem:** Eve with a quantum computer can break public key cryptography and learn Alice's message  


Luckily, when one door closes (public key cryptography) another door opens (quantum cryptography)

To do quantum cryptography, we need quantum particles. There are many types of quantum particles, but for cryptography, it makes sense to use *photons* - individual particles of light. Photons are:

- Fast (good!)
- Easily lost in fiber-optic cables, in atmosphere (bad!)
- Hard to create and detect (bad!)

## Photons and Polarizers

::: {.callout-tip appearance="simple"}

### ABCD Question 

If I insert a diagonal polarized filter (diagonal polarizer) between a horizontal and vertically oriented filter, how much light will come through?

A) Same as with no diagonal filter inserted
A) Less than with a single filter
A) The same as with a single filter
A) More than with a single filter

:::

The following describe interactions between photons and polarizers 

* A vertically polarized photon encounters a vertically polarized filter: 
  - A vertically polarized photon exits the filter   
* A horizontally polarized photon encounters a vertically polarized filter: 
  - No photon exits the filter   
* A horizontally polarized photon encounters a vertically polarized filter:  

  - With 1/2 probability, a vertically polarized photon exits   
  - With 1/2 probability, no photon exits   

If you've never studied quantum before, your intuition for the final scenario was probably wrong! We think of the vertical filter as asking the question, "Is this photon vertically or horizontally polarized?" and then asking this question forces the photon 
to "choose" to be vertically or horizontally polarized. To make the "decision," the photon flips a coin (50/50 probability).

Here are two rules to help you generalize the above interactions to new situations:

 - The behavior of the photon only depends on the angle between photon polarization and the angle of the polarizer
 - If a photon exits a polarized filter, it must have the same polarization as the polarizer.

::: {.callout-tip appearance="simple"}

## Group Exercise

Ice breaker: what do you do to relax?

Main question: Explain our experiment using your new understanding of photons and polarizers:

![Diagram of polarizer experiment, with unpolarized lightbulb followed by a vertical polarizer labelled A, a diagonal polarizer labeled B, and a horizontal polarizer labeled C](QuartoImages/Polarizer_Experiment.png)

You should assume that each photon out of the bulb has a random polarization.

* What polarizations(s) to exiting photons have?  
* If $T$ photons hit polarizer $B$, on average how many photons will exit polarizer C?
:::

### Quantum Measurement Terminology

* A polarizer is a type of **quantum measurement**. It "asks" whether a photon is polarized in the direction of the polarizer or at 90 degrees to the direction of the polarized filter. 
* A quantum measurement changes the particle being measured. (In the case of the vertical polarizer, it forces the photon to have either vertical or horizontal polarization, regardless of the original photon polarization.)  We call this change of the state due to measurement **collapse**
* A **measurement outcome** is the an output states of a measurement (in the case of a vertical polarizer, the possible measurement outcomes are a vertically polarized photon or a horizontally polarized photon.) You can not pick the measurement outcome - each possible measurement outcome has a probability associated with it that depends on the measurement and the input state.


If we wanted to actually learn the outcome of a polarizer measurement, we could set up a photon detector after the polarizer, and if the detector goes off, we would know that the photon passed through the filter, and so had the same polarization as the filter. 

![Diagram of photon encountering a vertical polarizer followed by a photon detector](QuartoImages/Detector.png){width=400}

The only way to get information out of a quantum system is through quantum measurements. but quantum measurements change the system (through collapse). Thus, unless the system is behaving classically (e.g. only vertical/horizontal photons and filters, no diagonal photons and filters) your measurements will always interfere with what you are measuring. 

This would be like trying to take the temperature, but the act of taking the temperature would change the temperature. Pretty strange!

::: {.callout-note}

Polarizers are a slightly strange measurement because in the case of a vertically polarized filter, if we get a measurement outcome of horizontally polarized, the process of measurement, in addition to causing a collapse to the horizontally polarized state also cases the photon to be destroyed/blocked by the filter, because vertically polarized filters block all horizontally polarized light. 

If we put a a photon detector after the filter, this type of measurement is called a destructive measurement, because it destroys the quantum state in the process of measuring it (either the photon is destroyed by the filter when it collapses to a polarization that is orthogonal to the filter, or it passes through the filter but then is destroyed when it encounters the detector.)
:::

## BB84 Quantum Cryptography Protocol

0) Alice and Bob pick $L\gg n$ (where recall $n$ is the length of the message she wants to send.)    
1) Alice chooses $a,b\in\{0,1\}^L$ randomly. At the $i^{th}$ time step she sends a photon to Bob. The polarization of the photon is chosen based on $a_i$, $b_i$, ($i^{th}$ bits of $a$ and $b$) using the following table:   

| $a$ (basis bit) | $b$ (info bit) | photon polarization | ket |   
|-----------------|----------------|--------|-----|   
| 0 | 0 | vertical | $\ket{0}$ |  
| 0 | 1 | horizontal | $\ket{1}$ | 
| 1 | 0 | / (right diagonal) | $\ket{+}=\frac{1}{\sqrt{2}}\ket{0}+\frac{1}{\sqrt{2}}\ket{1}$ |  
| 1 | 1 | \ (left diagonal) | $\ket{-}=\frac{1}{\sqrt{2}}\ket{0}-\frac{1}{\sqrt{2}}\ket{1}$ |  

2) Bob chooses $c\in\{0,1\}^L$ randomly. At the $i^{th}$ time step he sets up a measurement based on $c_i$ using the following table:

| $c$ (measurement basis) |  measurement| ket |   
|-----------------|--------|-----|   
| 0 | vertical polarizer followed by photon detector | $\{\ket{0},\ket{1}\}$ |  
| 1 | right diagonal polarizer followed by photon detector |$\{\ket{+},\ket{-}\}$| 

3) Bob records the outcome of his measurement in the string $d$, as:

$$ d_i= 
\begin{cases}
0 & \textrm{ if detection}\\
1 & \textrm{ if no detection}
\end{cases}
$$

::: {.callout-tip}

## Example

$L=2$, $a=01$, $b=11$, $c=11$.

Then Alice first sends a horizontally polarized photon to Bob, who measures it with a right diagonal filter. In this scenario, there is a 50/50 chance of detection, so $d_1$ will either be $0$ or $1$ with equal probability. 

Then Alice sends a left diagonally polarized photon to Bob, who measures it with a right diagonal filter. In this scenario, there is a 0 chance of detection, so $d_2=1$.

Thus, in this example, Bob will either have $d=01$ or $d=11.$
:::



::: {.callout-tip appearance="simple"}

### ABCD Questions

If $a_i=c_i$ then

A) $b_i=d_i$
A) $b_i\neq d_i$
A) $b_i=d_i$ half of the time

If $a_i\neq c_i$ then

A) $b_i=d_i$
A) $b_i\neq d_i$
A) $b_i=d_i$ half of the time


:::


4) Alice and Bob publicly announce $a$ and $c$ strings.

5) Alice and Bob throw out the bits of $b,d$ corresponding to bits where $a\neq c$. The remaining bits ($b'$ for Alice, $d'$ for Bob) should be their secret key. (We should have $b'=d'$.)

### What about Eve??!!

Here is a possible strategy for Eve. They chooses $e\in\{0,1,2\}^L$ in the most malicious way possible. At the $i^{th}$ time step they set up a measurement based on $e_i$ using the following table:

| $e$  |  measurement| 
|-----------------|--------|-----|   
| 0 | vertical polarizer followed by photon detector | 
| 1 | right diagonal polarizer followed by photon detector |
| 2 | lets the photon pass undisturbed | 

If $e_i\in\{0,1\}$:  

* If they get a detection, they send to Bob a photon with the polarization of their polarizing filter.  (For example, if they are measuring with a vertical polarizer and gets a detection, they send a vertically polarized photon to Bob.)
* If they do not get a detection, they send to Bob a photon with a polarization 90 degrees away from that of their filter. (For example, if they are measuring with a vertical polarizer and do not get a detection, they send a horizontally polarized photon to Bob.)

Eve records their outcome in the string $f:$
$$ f_i= 
\begin{cases}
0 & \textrm{ if detection}\\
1 & \textrm{ if measure but no detection} \\
2 & \textrm{ if no measurement}
\end{cases}
$$

::: {.callout-tip appearance="simple"}

### Group Exercise

Ice breaker: What clubs/sports/activities do you participate in at Midd?

* Simulate what happens to Alice and Bob's strings when Eve interferes by filling out the blank columns in the $f$ and $d$ rows in this [worksheet](QuartoImages/CryptoHandoutImproved.pdf).  
* What happens to Alice and Bob's "secret" key? ($b/d$ strings)

:::

We see that the more Eve interferes (chooses $e_i$ to be $0$ or $1$), the more $b'\neq d'$. This seems bad, because Alice and Bob's shared secret key should be the same. And also, now Eve knows information about $b'$ and $d'$, even though these should be secret. This seems bad!! How do we make this ok?

To deal with Eve's interference or possible interference, Alice and Bob need to add a few more steps to their protocol:

6) Alice and Bob make public a random subset of the bits of $b'$ and $d'$. If Eve did not interfere, these should all be the same. If they interfere a lot, $b'$  and $d'$ will be somewhat different. By counting how many of these public bits are the same, they can estimate how often Eve interfered, and consequently, they can estimate how much information Eve knows about the rest (the as yet unpublicized bits) of $b$ and $d$ (which we call $b''$, $d''$). Now if there are a lot of mismatches, Alice and Bob decide that Eve knows too much, and they abort the protocol. This is the equivalent of Eve jamming their signal. However, if there are not too many mismatches, they conclude Eve does not know very much about their remaining bits, and they decide to continue.

7) Alice and Bob perform an error correction protocol on $b''$ and $d''$ to end up with an identical string $s'$ that they each possess. (The details of this protocol are beyond the scope of this class.) The important things to know about this error correction protocol are:     

  * $|s'|<|b'|,|d'|$ (they lose bits in the process)  
  * Eve learns some additional information about $s'$ in this process because they know what error correction protocol Alice and Bob are using, but they do not learn too much information

8) Alice and Bob perform privacy amplification. They do this by applying a hash function to $s'$ to produce a string $s$. The important things to know:  
* $|s'|<|s|$ (they lose bits of their secret key in the process)  
* Eve knows nothing about $s'$, even though they had some information about $s$ and knows the hashing function used.


::: {.callout-tip appearance="simple"}

### Group Exercise

Ice breaker: Song of the summer?

* Talk through the BB84 protocol. Try to explain each part, what is going on, and why.
* Create a list of questions that you can not answer as a group
* BB84 creates a secret key that is guaranteed secure from any eavesdropper. What is the quantum secret sauce that allows this?

:::