-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
498 lines (473 loc) · 24.4 KB
/
index.html
File metadata and controls
498 lines (473 loc) · 24.4 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<!doctype html>
<html lang="en" class="h-full">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/encryption.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/style.css" />
<title>Codebreaker</title>
</head>
<body class="bg-gray-100 font-sans min-h-screen items-center justify-center px-6 py-3 h-full w-full">
<div
id="game"
x-data="game"
@keyup.window="onKeyPress($event.key)"
@keydown.escape="settingsModal = false"
class="container mx-auto h-full flex flex-col flex-1"
>
<header class="flex justify-between items-center bg-white shadow-md rounded-md py-4 px-8 mb-5 print:hidden">
<span class="inline-flex items-center">
<img src="encryption.svg" alt="Codebreaker" class="h-10 w-10" />
<span class="font-bold ml-2 hidden md:block">Codebreaker</span>
</span>
<nav class="flex">
<ul class="flex flex-row gap-1">
<!-- cipher selector -->
<li>
<div class="flex justify-center">
<div
x-data="{
open: false,
toggle() {
if (this.open) {
return this.close()
}
this.$refs.button.focus()
this.open = true
},
close(unfocusAfter) {
if (! this.open) return
this.open = false
unfocusAfter && unfocusAfter.blur()
}
}"
x-on:keydown.escape.prevent.stop="close($refs.button)"
x-on:focusin.window="! $refs.panel.contains($event.target) && close()"
x-id="['cipher-dropdown']"
class="relative"
>
<button
x-ref="button"
x-on:click="toggle()"
:aria-expanded="open"
:aria-controls="$id('cipher-dropdown')"
type="button"
class="flex items-center gap-2 bg-white w-48 px-5 py-2.5 rounded-md shadow-sm"
>
<span x-text="ciphers[cipher].name"></span>
<!-- Heroicon: chevron-down -->
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5 text-gray-400 ml-auto"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clip-rule="evenodd"
/>
</svg>
</button>
<div
x-ref="panel"
x-show="open"
x-transition.origin.top.left
x-on:click.outside="close($refs.button)"
:id="$id('cipher-dropdown')"
style="display: none"
class="absolute left-0 mt-2 w-40 rounded-md bg-white shadow-md z-50"
>
<template x-for="(item, index) in ciphers">
<a
href="#"
@click="cipher=index; close($refs.button)"
class="flex items-center gap-2 w-full first-of-type:rounded-t-md last-of-type:rounded-b-md px-4 py-2.5 text-left text-sm hover:bg-gray-50 disabled:text-gray-500"
x-text="ciphers[index].name"
></a>
</template>
</div>
</div>
</div>
</li>
<!-- alphabet selector -->
<li>
<div class="flex justify-center">
<div
x-data="{
open: false,
toggle() {
if (this.open) {
return this.close()
}
this.$refs.button.focus()
this.open = true
},
close(unfocusAfter) {
if (! this.open) return
this.open = false
unfocusAfter && unfocusAfter.blur()
}
}"
x-on:keydown.escape.prevent.stop="close($refs.button)"
x-on:focusin.window="! $refs.panel.contains($event.target) && close()"
x-id="['language-dropdown']"
class="relative"
>
<button
x-ref="button"
x-on:click="toggle()"
:aria-expanded="open"
:aria-controls="$id('language-dropdown')"
type="button"
class="flex items-center gap-2 bg-white w-32 px-5 py-2.5 rounded-md shadow-sm"
>
<span x-text="symbolSets[fromSymbolSet].name"></span>
<!-- Heroicon: chevron-down -->
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5 text-gray-400 ml-auto"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clip-rule="evenodd"
/>
</svg>
</button>
<div
x-ref="panel"
x-show="open"
x-transition.origin.top.left
x-on:click.outside="close($refs.button)"
:id="$id('language-dropdown')"
style="display: none"
class="absolute left-0 mt-2 w-40 rounded-md bg-white shadow-md z-50"
>
<template x-for="language in languages">
<a
href="#"
@click="fromSymbolSet=language; close($refs.button)"
class="flex items-center gap-2 w-full first-of-type:rounded-t-md last-of-type:rounded-b-md px-4 py-2.5 text-left text-sm hover:bg-gray-50 disabled:text-gray-500"
x-text="symbolSets[language].name"
></a>
</template>
</div>
</div>
</div>
</li>
<!-- print -->
<li>
<span class="sr-only">Print</span>
<button @click="window.print()" class="inline-flex py-2 px-2 hover:bg-slate-200 rounded-sm">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M6.72 13.829c-.24.03-.48.062-.72.096m.72-.096a42.415 42.415 0 0 1 10.56 0m-10.56 0L6.34 18m10.94-4.171c.24.03.48.062.72.096m-.72-.096L17.66 18m0 0 .229 2.523a1.125 1.125 0 0 1-1.12 1.227H7.231c-.662 0-1.18-.568-1.12-1.227L6.34 18m11.318 0h1.091A2.25 2.25 0 0 0 21 15.75V9.456c0-1.081-.768-2.015-1.837-2.175a48.055 48.055 0 0 0-1.913-.247M6.34 18H5.25A2.25 2.25 0 0 1 3 15.75V9.456c0-1.081.768-2.015 1.837-2.175a48.041 48.041 0 0 1 1.913-.247m10.5 0a48.536 48.536 0 0 0-10.5 0m10.5 0V3.375c0-.621-.504-1.125-1.125-1.125h-8.25c-.621 0-1.125.504-1.125 1.125v3.659M18 10.5h.008v.008H18V10.5Zm-3 0h.008v.008H15V10.5Z"
/>
</svg>
</button>
</li>
<!-- trash -->
<li>
<span class="sr-only">Reset</span>
<a href="#" @click="reset()" class="inline-flex py-2 px-2 hover:bg-slate-200 rounded-sm">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0"
/>
</svg>
</a>
</li>
<!-- settings -->
<li>
<span class="sr-only">Settings</span>
<button class="inline-flex py-2 px-2 hover:bg-slate-200 rounded-sm" @click="settingsModal = !settingsModal">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z"
/>
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
</svg>
</button>
<div
class="fixed inset-0 z-30 flex items-center justify-center overflow-auto bg-black bg-opacity-50"
x-show="settingsModal"
>
<div
class="max-w-3xl px-6 py-6 mx-auto text-left bg-white rounded-sm shadow-lg"
@click.away="settingsModal = false"
x-transition:enter="motion-safe:ease-out duration-300"
x-transition:enter-start="opacity-0 scale-90"
x-transition:enter-end="opacity-100 scale-100"
>
<div class="flex items-center justify-center">
<form x-on:submit.prevent="">
<div>
<label for="message" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>Message</label
>
<textarea
id="message"
x-model="message"
@keypress.prevent=""
rows="3"
cols="40"
class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
></textarea>
</div>
<template x-if="ciphers[cipher].seed">
<div class="pt-2">
<label for="message" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>Seed</label
>
<div class="flex flex-row align-middle gap-1">
<input
x-model.number="seed"
type="number"
min="0"
max="4294967295"
step="1"
class="float-left p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
/>
<button @click="randomSeed()" class="float-right">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99"
/>
</svg>
</button>
</div>
</div>
</template>
<template x-if="ciphers[cipher].steps">
<div class="pt-2">
<label for="message" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>Steps</label
>
<div class="flex flex-row align-middle gap-1">
<input
x-model.number="steps"
type="number"
min="1"
max="30"
step="1"
class="float-left p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
/>
<button @click="randomSteps()" class="float-right">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99"
/>
</svg>
</button>
</div>
</div>
</template>
<template x-if="ciphers[cipher].keyword">
<div class="pt-2">
<label for="message" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>Keyword</label
>
<div class="flex flex-row align-middle gap-1">
<input
x-model.number="keyword"
type="text"
class="float-left p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
/>
</div>
</div>
</template>
</form>
</div>
</div>
</div>
</li>
<!-- info -->
<li>
<span class="sr-only">Info</span>
<button class="inline-flex py-2 px-2 hover:bg-slate-200 rounded-sm" @click="infoModal = !infoModal">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"
/>
</svg>
</button>
<div
class="fixed inset-0 z-30 flex items-center justify-center overflow-auto bg-black bg-opacity-50"
x-show="infoModal"
>
<div
class="max-w-3xl px-6 py-6 mx-auto text-left bg-white rounded-sm shadow-lg"
@click.away="infoModal = false"
x-transition:enter="motion-safe:ease-out duration-300"
x-transition:enter-start="opacity-0 scale-90"
x-transition:enter-end="opacity-100 scale-100"
>
<div class="m-10">
<h1 class="text-xl font-bold pb-2">What is Codebreaker?</h1>
<div class="space-y-3">
<p>
Codebreaker is a tool for creating crypto puzzles. There are multiple ciphers available to
choose from.
</p>
<p>
Choose a cipher and write a message. When you're happy with the result, print it out on paper!
</p>
<p class="">
A few suggestions on how to use the printed paper, ranged from easiest to hardest to solve:
</p>
<ul class="list-disc list-inside mt-0">
<li>Keep the cipher key attached</li>
<li>Cut away the cipher key, but give hints by deciphering one or more characters</li>
<li>Cut away the cipher key</li>
</ul>
<p class="italic">
Please note that Codebreaker is built for using on a computer with a keyboard and printer. If it
works on any other device it's a happy accident.
</p>
</div>
</div>
</div>
</div>
</li>
</ul>
</nav>
</header>
<section id="coded-message" class="bg-white shadow-md rounded-md gap-5 py-4 mb-5 print:shadow-none print:mt-auto">
<div class="flex flex-col gap-7">
<template x-for="(line,lineIndex) in lines">
<div class="mx-2 text-2xl uppercase justify-center text-center break-after-all">
<template x-for="(word,wordIndex) in line">
<div class="inline-flex mx-2 mb-2 text-2xl uppercase text-center break-after-auto">
<template x-for="(character,characterIndex) in word">
<div class="inline break-inside-avoid">
<template x-if="isCursor(decodedLines[lineIndex][wordIndex][characterIndex])">
<div class="flex flex-col items-center justify-center gap-x-3 gap-y-5 mx-2 print:hidden">
<span :class="toSymbolSetFont"> </span>
<div class="size-10" :class="fromSymbolSetFont">
<span class="text-gray-500 animate-pulse duration-300">█</span>
</div>
</div>
</template>
<template x-if="!isCursor(decodedLines[lineIndex][wordIndex][characterIndex])">
<div class="flex flex-col items-center justify-center gap-x-3 gap-y-5 mx-2">
<span x-text="character" :class="toSymbolSetFont"></span>
<div class="size-10 border-b-2 border-gray-500" :class="fromSymbolSetFont">
<span
class="text-gray-200 print:hidden"
x-text="decodedLines[lineIndex][wordIndex][characterIndex]"
></span>
</div>
</div>
</template>
</div>
</template>
</div>
</template>
</div>
</template>
</div>
</section>
<section
id="legend"
class="bg-white shadow-md rounded-md p-4 mt-auto print:shadow-none print:break-inside-avoid-page print:w-full print:border-t border-dashed break-before-auto break-inside-avoid-page"
>
<div class="flex flex-wrap justify-center print:w-full gap-y-5">
<template x-for="(symbol,character) in legend">
<div class="flex flex-col items-center border-l last:border-r border-black/10 print:border-gray-400">
<span
class="w-10 print:w-8 text-2xl uppercase text-center"
x-text="character"
:class="fromSymbolSetFont"
></span>
<span
class="w-10 print:w-8 text-2xl uppercase text-center"
x-text="symbol"
:class="toSymbolSetFont"
></span>
</div>
</template>
</div>
</section>
<footer class="flex justify-center bg-gray-200/50 shadow-md rounded-md py-4 px-8 mt-5 print:hidden">
<a
href="https://github.com/mld/codebreaker"
target="_blank"
rel="noopener noreferrer"
class="text-gray-500 hover:text-gray-700"
>
<span class="sr-only">GitHub</span>
<svg
class="h-6 w-6 flex-no-shrink fill-current"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 100 100"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
/>
</svg>
</a>
</footer>
</div>
<script type="module" src="/main.js"></script>
</body>
</html>