In this Notebook, we will just explore a way of playing Toss Coin remotely using Quantum Toss Coin. This is only an implementation of the problem presented by Physics Girl in this video.

2 people (Alice and Bob) want to take a decision but they disagree. They decide to to decide the issue by playing Coin flipping. It it's tail, Alice's solution is taken, else it's Bob's one. However there is a problem. They are not at the same place. How the second person (remotely) can be sure that the first one is not cheating ? A quantum Toss Coin ... of course :D. But first, let's explain quickly how polarized light is working.

In nature, the light is polarized in all direction (For this problem; let's keep only the 4 main direction :

- Vertical (V)
- Horizontal (H)
- Diagonal Ascending (D1)
- Diagonal Descending (D2)

When a light is polarized "V", a photon with this polarization passes through :

- a "V" filter in 100% of cases.
- a "H" filter in 0% of cases.
- a "D1" filter in 50% of cases.
- a "D2" filter in 50% of cases.

And this mechanics is the same for all filter orientation vs Light polarization

To play a Quantum Toss Coin game, Alice will generate a Binary Code. She will decide about a bank of filter :

- "V" and "H"
- "D1" and "D2"

She will generate a set of photon oriented:

- "V" or "D1" if the bit is 0
- "H" or "D2" if the bit is 1

Those photons are transfered to Bob.

As it is light, Bob cannot use both set of filters (because he can check a photon only once). As a result he randomly choose a set of filter. If the light passes through the filter, he write 1 else 0.

Now Bob is in front of 2 partial codes. He has to choose 1 set of filters and say it to Alice. With no more information there is 50%/50% chance of finding the right one.

Alice can now say if Bob found the correct set of filters or not. To confirm, Alice can now say out loud the code. It should match the partial code using the 1 set of filter. Alice cannot cheat as the other code is randomly assigned.

They finally play remotely at Toss Coin !

Now we can simulate it easily

In [109]:

```
import random
```

In [110]:

```
# this table store the probability of a photon with a given orientation passe through a filter of a given orientation
table = {
"V" : {
"V" : 1,
"H" : 0,
"D1" : 0.5,
"D2" : 0.5
},
"H" : {
"V" : 0,
"H" : 1,
"D1" : 0.5,
"D2" : 0.5
},
"D1" : {
"V" : 0.5,
"H" : 0.5,
"D1" : 1,
"D2" : 0
},
"D2" : {
"V" : 0.5,
"H" : 0.5,
"D1" : 0,
"D2" : 1
},
}
filter_bank = [
["V", "H"],
["D1", "D2"]
]
```

In [111]:

```
def encode(word, filter_):
# Encode the message to photon
return [filter_[i] for i in word]
def decode(message, filter1, filter2):
# Decode randomly each photon with a set of filter
m1, m2 = [], []
for x in message:
if random.random() > 0.5:
m1.append(1 if random.random() >= table[x][filter1[0]] else 0)
m2.append("_")
else:
m1.append("_")
m2.append(1 if random.random() >= table[x][filter2[0]] else 0)
return "".join(map(str, m1)), "".join(map(str, m2))
```

In [112]:

```
# message length
l = 100
```

In [115]:

```
word = [0 if random.random() >=0.5 else 1 for i in range(l)]
```

In [116]:

```
photons = encode(word, filter_bank[0])
```

In [117]:

```
c1, c2 = decode(photons, filter_bank[0], filter_bank[1])
```

In [122]:

```
print("Message created by Alice")
print("".join(map(str, word)))
print("\nMessages received by Bob")
print("Rectilinear filter :\n{}".format(c1))
print("Diagonal filter :\n{}".format(c2))
```

If we compare digit by digit, only the partial code created with Rectilinear filter matches the Initial Code

In [123]:

```
word = [0 if random.random() >=0.5 else 1 for i in range(l)]
```

In [124]:

```
message = encode(word, filter_bank[1])
c1, c2 = decode(message, filter_bank[0], filter_bank[1])
```

In [125]:

```
print("Message created by Alice")
print("".join(map(str, word)))
print("\nMessages received by Bob")
print("Rectilinear filter :\n{}".format(c1))
print("Diagonal filter :\n{}".format(c2))
```

Here, it's the reverse, only the diagonal matches.

In this small notebook, we explored how we could use Quantum physics to play remotely Coin Flipping game using light polarization. However, this remain purely experimental are we are not able to transfer photons but still.