-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
231 lines (219 loc) · 8.45 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<html>
<head>
<title>Jeu QKD</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/uikit.min.css" />
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit-icons.min.js"></script>
<script src="https://unpkg.com/vue@3"></script>
<style>
html {
background: black;
padding : 0px ;
margin : 0px ;
width : 100hv ;
height : 100hv;
/* color: white; */
}
.centralImage {
width: 100%;
max-width: 550px;
}
/* Pour les images superposées quand on triche */
.cheating-container {
position: relative;
display: inline-block;
padding: 0px;
margin: 0px;
}
.cheating-img {
position: absolute;
top: 0;
left: 0;
opacity: .5;
}
.game-container {
text-align: center;
}
.envoyer {
background-color: green;
}
</style>
</head>
<body class="uk-light">
<div id="app" class="uk-section uk-container">
<h1>Jeu de distribution quantique de clés (QKD)</h1>
<p>Bienvenue dans ce mini-jeu ayant pour vocation d'illustrer la distribution quantique de clé (QKD). Générez des qubits sur votre téléphone, envoyez-le à un⋅e ami⋅e et retrouvez ensemble une clé secrète ! Mais attention de ne pas vous faire avoir par un adversaire un peu trop curieux…</p>
<p>Nombre d'instances: {{nb_copies}} <button class="uk-button uk-button-default uk-button-small" @click="nb_copies=Math.max(1,nb_copies-1)">-</button> <button class="uk-button uk-button-default uk-button-small" @click="nb_copies++">+</button></p>
<div v-for="index in nb_copies">
<game :instance="index"></game>
</div>
</div>
<script type="text/x-template" id="template-game">
<div class="game-container">
<!-- Preload images, or it will give ugly "shaking/scrolling" effects when moving in the page -->
<div v-if="step=='preparation'">
<h2><span class="uk-badge" v-if="instance>0">{{instance}}</span> Étape 1: Alice prépare l'état</h2>
<p>
<img :src="images[internal_state]"
:alt="strFromState"
class="centralImage" />
</p>
<p >
Etat:
<button class="uk-button uk-button-default" @click="toggleHV">{{internalHorV}}</button> <button class="uk-button uk-button-default" @click="toggle01">{{internal0or1}}</button> <button class="uk-button uk-button-danger" @click="envoyer">Envoyer !</button>
</p>
</div>
<div v-if="step=='sending'">
<h2><span class="uk-badge" v-if="instance>0">{{instance}}</span> Étape 2: Envoie du qubit en cours…</h2>
<p>
<img :src="images.sending"
alt="Envoie en cours"
class="centralImage" />
</p>
<p>
Donnez votre téléphone/ordinateur à Bob… ou à l'adversaire. <button class="uk-button uk-button-danger" @click="bienRecu"> Bien reçu !</button>
</p>
</div>
<div v-if="step=='choose_measurement'">
<h2><span class="uk-badge" v-if="instance>0">{{instance}}</span> Étape 3: Bob (ou l'adversaire) mesure</h2>
<p class="cheating-container">
<img :src="images['measure'+measurement_basis]"
:alt="'Mesure base ' + measurementHorV"
class="centralImage" />
<img v-if="cheating"
:src="images[internal_state]"
:alt="'Mesure base ' + measurementHorV"
class="centralImage cheating-img" />
</p>
<p>
Choix de la base: <button class="uk-button uk-button-default" style="min-width: 22ex;" @click="toggleMeasurement">{{measurementHorV}}</button> <button class="uk-button uk-button-danger" @click="mesurer">Mesurer !</button> Tricher: <button class="uk-button uk-button-default" @click="toggleCheating">{{cheating?'Oui':'Non'}}</button><br/>
</p>
</div>
<div v-if="step=='outcome'">
<h2><span class="uk-badge" v-if="instance>0">{{instance}}</span> Étape 3: La mesure donne…</h2>
<p>
<img :src="images['outcome'+measurement_outcome]"
:alt="'Résultat mesure: '+measurement_outcome"
class="centralImage" />
</p>
<p>
À vous de bien utiliser ce résultat pour obtenir une clé secrète ;-) Si vous êtes un adversaire, continuez en vous faisant passer pour Alice auprès de Bob!
<button class="uk-button uk-button-danger" @click="restart">Continuer !</button>
</p>
</div>
<div v-for="image in images">
<link rel="preload" :href="image" as="image">
</div>
</div>
</script>
<script>
const GameComponent = {
template: '#template-game',
props: {
// If non zero, describe the instance number
instance: {
type: Number,
default: 0
},
},
data() {
return {
// step must be in preparation/sending/choose_measurement/outcome
step: 'preparation',
// 0 = |0>, 1 = |1>, 2 = |+>, 3 = |->
internal_state: 0,
measurement_basis: 0,
measurement_outcome: 0,
cheating: false,
images: {
// States: 0/1/2/3 = |0>/|1>/|+>/|->
0: "images/0000.jpg",
1: "images/0001.jpg",
2: "images/0002.jpg",
3: "images/0003.jpg",
"sending": "images/0005.jpg",
// Basis V
"measure0": "images/0006.jpg",
// Basis H
"measure1": "images/0007.jpg",
"outcome0": "images/0008.jpg",
"outcome1": "images/0009.jpg"
},
}
},
computed: {
strFromState: function () {
switch (this.internal_state) {
case 0:
return "|0>";
case 1:
return "|1>";
case 2:
return "|+>";
case 3:
return "|->";
}
},
internalHorV: function () {
return (this.internal_state < 2) ? "Vertical" : "Horizontal"
},
internal0or1: function () {
return this.internal_state % 2
},
measurementHorV: function () {
return (this.measurement_basis == 0) ? "Vertical" : "Horizontal"
},
},
methods: {
toggleHV: function (event) {
this.internal_state = (this.internal_state + 2) % 4
},
toggle01: function (event) {
this.internal_state = (this.internal_state % 2 == 0) ? this.internal_state + 1 : this.internal_state - 1
},
envoyer: function (event) {
this.step = "sending"
},
bienRecu: function (event) {
this.step = "choose_measurement"
},
toggleMeasurement: function (event) {
this.measurement_basis = (this.measurement_basis + 1) % 2
},
toggleCheating: function (event) {
this.cheating = !this.cheating
},
mesurer: function (event) {
// Check if the basis is good
if ((this.internal_state < 2 && this.measurement_basis == 0)
|| (this.internal_state >= 2 && this.measurement_basis == 1))
{
this.measurement_outcome = this.internal_state % 2
}
else { // We measure in the wrong basis: random outcome
this.measurement_outcome = (Math.random()>=0.5)? 1 : 0
}
this.step = "outcome"
},
restart: function (event) {
this.step = "preparation";
this.internal_state = 0;
this.measurement_basis = 0;
this.measurement_outcome = 0;
}
}
}
Vue.createApp({
data() {
return {
nb_copies: 1,
};
}
}).component("game", GameComponent).mount('#app')
</script>
</body>
</html>