Repository navigation
Expand file tree
/
Copy pathchallenges.html
More file actions
411 lines (388 loc) · 26.1 KB
/
Copy pathchallenges.html
File metadata and controls
411 lines (388 loc) · 26.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cipher Challenges — The Cipher Museum</title>
<meta name="description" content="Break real ciphers. Ten progressively harder challenges — from Caesar to Enigma.">
<meta property="og:title" content="Cipher Challenges — The Cipher Museum">
<meta property="og:description" content="Break real ciphers. Ten progressively harder challenges — from Caesar to Enigma.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://ciphermuseum.com/challenges.html">
<meta property="og:image" content="https://ciphermuseum.com/images/og/og-default.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="The Cipher Museum — an interactive history of encryption">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Cipher Challenges — The Cipher Museum">
<meta name="twitter:description" content="Break real ciphers. Ten progressively harder challenges — from Caesar to Enigma.">
<meta name="twitter:image" content="https://ciphermuseum.com/images/og/og-default.png">
<meta name="theme-color" content="#0a0a0f">
<link rel="canonical" href="https://ciphermuseum.com/challenges.html">
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<link rel="manifest" href="manifest.webmanifest">
<link rel="stylesheet" href="css/museum.css">
<style>
.challenges-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:1.5rem;max-width:1200px;margin:0 auto}
@media(max-width:768px){
.challenges-grid{grid-template-columns:1fr}
.ch-card{max-width:100%;overflow:hidden}
.ch-input-row{flex-direction:column}
.ch-submit{width:100%;min-height:44px}
.ch-input{min-height:44px;font-size:1rem}
.ch-hint-btn{min-height:44px;padding:.6rem 1rem}
.ch-ciphertext{font-size:.78rem;letter-spacing:.1em;padding:.75rem;word-break:break-all;overflow-wrap:break-word}
.ch-header{flex-wrap:wrap}
.ch-body{padding:1rem}
}
.ch-card{background:var(--s2);border:1px solid var(--s4);border-radius:var(--rl);overflow:hidden;transition:all var(--trs)}
.ch-card:hover{border-color:var(--gold-b);transform:translateY(-2px);box-shadow:var(--sh)}
.ch-card.locked{opacity:.55;pointer-events:none}.ch-card.solved{border-color:var(--green)}
.ch-header{padding:1.5rem;border-bottom:1px solid var(--s4);display:flex;align-items:center;gap:1rem}
.ch-level{width:42px;height:42px;border-radius:50%;border:2px solid var(--gold-dim);display:flex;align-items:center;justify-content:center;font-family:var(--fm);font-size:1rem;font-weight:700;color:var(--gold);flex-shrink:0}
.ch-card.solved .ch-level{border-color:var(--green);color:var(--green);background:rgba(90,200,160,.1)}
.ch-meta h3{font-family:var(--fd);font-size:1.1rem;color:var(--tx);letter-spacing:.04em;margin-bottom:.2rem}
.ch-meta span{font-family:var(--fm);font-size:.58rem;letter-spacing:.15em;text-transform:uppercase;color:var(--tx3)}
.ch-body{padding:1.5rem}
.ch-prompt{font-size:.95rem;color:var(--tx2);line-height:1.75;margin-bottom:1.25rem}
.ch-ciphertext{font-family:var(--fm);font-size:.88rem;letter-spacing:.15em;color:var(--tx);background:var(--s3);border:1px solid var(--s5);border-radius:var(--r);padding:1rem;margin-bottom:1.25rem;word-break:break-all;line-height:1.8}
.ch-input-row{display:flex;gap:.75rem;margin-bottom:1rem}
.ch-input{flex:1;background:var(--s3);border:1px solid var(--s5);border-radius:var(--r);color:var(--tx);font-family:var(--fm);font-size:.88rem;padding:.65rem 1rem;outline:none;transition:border-color var(--tr)}
.ch-input:focus{border-color:var(--gold-dim)}
.ch-submit{font-family:var(--fd);font-size:.72rem;letter-spacing:.1em;text-transform:uppercase;padding:.65rem 1.25rem;border:none;border-radius:var(--r);background:var(--gold);color:var(--black);font-weight:700;cursor:pointer;transition:all var(--tr);white-space:nowrap}
.ch-submit:hover{background:var(--gold-lt)}
.ch-feedback{font-family:var(--fm);font-size:.7rem;letter-spacing:.08em;padding:.5rem .75rem;border-radius:var(--r);display:none;margin-bottom:1rem}
.ch-feedback.wrong{display:block;background:var(--red-d);border:1px solid var(--red-b);color:var(--red)}
.ch-feedback.correct{display:block;background:rgba(90,200,160,.1);border:1px solid rgba(90,200,160,.3);color:var(--green)}
.ch-hint-btn{font-family:var(--fm);font-size:.6rem;letter-spacing:.1em;text-transform:uppercase;color:var(--tx3);background:none;border:1px solid var(--s5);border-radius:var(--r);padding:.4rem .8rem;cursor:pointer;transition:all var(--tr)}
.ch-hint-btn:hover{border-color:var(--gold-dim);color:var(--tx2)}
.ch-hint{font-size:.88rem;color:var(--tx2);line-height:1.7;padding:.75rem 1rem;background:var(--s3);border-radius:var(--r);margin-top:.75rem;display:none;border-left:3px solid var(--gold-dim)}
.ch-hint.visible{display:block}
.ch-walkthrough{display:none;margin-top:1rem;padding:1rem;background:var(--s3);border:1px solid var(--s4);border-radius:var(--r)}
.ch-walkthrough.visible{display:block}
.ch-walkthrough h4{font-family:var(--fd);font-size:.85rem;color:var(--gold);margin-bottom:.5rem;letter-spacing:.06em}
.ch-walkthrough p{font-size:.88rem;color:var(--tx2);line-height:1.75}
.ch-progress{max-width:1200px;margin:0 auto 2rem;display:flex;align-items:center;gap:.75rem;padding:1.25rem 1.5rem;background:var(--s2);border:1px solid var(--s4);border-radius:var(--rl)}
.ch-progress-bar{flex:1;height:6px;background:var(--s4);border-radius:3px;overflow:hidden}
.ch-progress-fill{height:100%;background:var(--gold);border-radius:3px;transition:width 500ms ease;width:0%}
.ch-progress-label{font-family:var(--fm);font-size:.62rem;letter-spacing:.12em;text-transform:uppercase;color:var(--tx3);white-space:nowrap}
.ch-share-btn{background:var(--s3);border:1px solid var(--s5);border-radius:var(--r);color:var(--tx2);font-family:var(--fm);font-size:.68rem;letter-spacing:.08em;padding:.45rem .8rem;cursor:pointer;white-space:nowrap;transition:border-color 150ms ease,color 150ms ease}
.ch-share-btn:hover{border-color:var(--gold);color:var(--gold)}
.ch-share-status{font-family:var(--fm);font-size:.68rem;color:var(--gold);white-space:nowrap}
.ch-congrats{display:none;max-width:800px;margin:2rem auto;text-align:center;padding:3rem;background:linear-gradient(135deg,rgba(201,168,76,.08),rgba(201,168,76,.02));border:1px solid var(--gold-b);border-radius:var(--rx)}
.ch-congrats.visible{display:block}
.ch-congrats h2{font-family:var(--fd);font-size:2rem;color:var(--gold);margin-bottom:1rem}
.ch-congrats p{font-size:1.05rem;color:var(--tx2);line-height:1.85;max-width:600px;margin:0 auto}
</style>
</head>
<body>
<a class="skip-link" href="#main-content">Skip to main content</a>
<nav class="museum-nav" aria-label="Primary">
<div class="nav-inner">
<a href="index.html" class="nav-logo">
<svg class="nav-logo-icon" viewBox="0 0 32 32" fill="none">
<circle cx="16" cy="16" r="14" stroke="currentColor" stroke-width="1.5"/>
<circle cx="16" cy="16" r="8" stroke="currentColor" stroke-width="1"/>
<circle cx="16" cy="16" r="2" fill="currentColor"/>
<line x1="16" y1="2" x2="16" y2="6" stroke="currentColor" stroke-width="1.5"/>
<line x1="16" y1="26" x2="16" y2="30" stroke="currentColor" stroke-width="1.5"/>
<line x1="2" y1="16" x2="6" y2="16" stroke="currentColor" stroke-width="1.5"/>
<line x1="26" y1="16" x2="30" y2="16" stroke="currentColor" stroke-width="1.5"/>
</svg>
<span class="nav-logo-text">The Cipher Museum</span>
</a>
<ul class="nav-links">
<li><a href="museum-map.html">Explore</a></li>
<li><a href="timeline.html">Timeline</a></li>
<li><a href="learn.html">Learn</a></li>
<li><a href="cipher-corpus.html">Cipher Corpus</a></li>
<li><a href="cryptanalysis.html">Cryptanalysis</a></li>
<li><a href="challenges.html">Challenges</a></li>
<li><a href="lab/workbench.html">Lab</a></li>
<li><a href="search.html">Search</a></li>
</ul>
</div>
</nav>
<main id="main-content" tabindex="-1">
<div class="page-hero">
<div class="breadcrumb">
<a href="index.html">Entrance</a><span>›</span>
Cipher Challenges
</div>
<span class="page-eyebrow">Test Your Skills</span>
<h1 class="page-title">Cipher Challenges</h1>
<p class="page-tagline">Ten encrypted messages across four difficulty tiers. Each solved challenge reveals a lesson about why classical ciphers fail.</p>
</div>
<section class="section">
<div class="ch-progress">
<span class="ch-progress-label" id="progress-text">0 of 10 solved</span>
<div class="ch-progress-bar"><div class="ch-progress-fill" id="progress-fill"></div></div>
<button type="button" id="share-progress" class="ch-share-btn" title="Copy a shareable summary of your progress">📋 Share</button>
<span id="share-status" role="status" aria-live="polite" class="ch-share-status"></span>
</div>
<div class="challenges-grid" id="challenges-container"></div>
<div class="ch-congrats" id="congrats">
<h2>🏆 Master Codebreaker</h2>
<p>You've completed all ten challenges on this page. The full message reads:</p>
<div class="ch-ciphertext" style="margin-top:1.5rem;color:var(--gold);letter-spacing:.12em;font-size:1rem;">
THE DIE IS CAST · KNOWLEDGE IS POWER · KNOW THYSELF · SECRETS HIDE IN PLAIN SIGHT · THE KEY IS PATIENCE · TRUST NO SINGLE LOCK · BREAK THE CODE NOW · THE BOMBE TURNS · PATIENCE CONQUERS ALL · FIRST CIPHER THEN KEY
</div>
<p style="margin-top:1rem;">These exercises illustrate weaknesses in selected classical systems. Solving them does not establish an attack on every museum exhibit or on modern cryptography.</p>
</div>
</section>
</main>
<footer></footer>
<script src="js/ciphers/all-engines.min.js"></script>
<script>
'use strict';
(function() {
const CHALLENGES = [
{
level: 1, cipher: 'Caesar', difficulty: 'Beginner',
prompt: 'This message was shifted by a fixed number of positions. Determine the shift and decrypt it.',
ciphertext: 'WKH GLH LV FDVW',
answer: 'THE DIE IS CAST',
lesson: 'Caesar ciphers have only 25 nonidentity shifts — all can be enumerated, although recognizing the intended plaintext can require context. This is why keyspace size matters.',
hints: [
'Caesar used a shift of 3. Try shifting each letter back by small numbers.',
'W→T, K→H, H→E… the shift is 3.'
],
walkthrough: 'Each letter is shifted forward by 3 positions: T→W, H→K, E→H. Shifting back by 3 gives an English rendering of the Latin phrase attributed to Julius Caesar: "THE DIE IS CAST" (Alea iacta est).'
},
{
level: 2, cipher: 'Atbash', difficulty: 'Beginner',
prompt: 'This cipher reverses the alphabet: A↔Z, B↔Y, C↔X… Decrypt it.',
ciphertext: 'PMLD GSBHVOU',
answer: 'KNOW THYSELF',
lesson: 'Atbash uses a fixed substitution with zero secret information — the "key" is the algorithm itself. Once the mapping is known, it provides no secret key to protect the text.',
hints: [
'A=Z, B=Y, C=X, D=W… Map each letter to its reverse.',
'P→K, M→N, L→O, D→W…'
],
walkthrough: 'Atbash maps A↔Z, B↔Y, C↔X, etc. P(16th)→K(11th), M(13th)→N(14th), L(12th)→O(15th), D(4th)→W(23rd). The answer is the ancient Greek aphorism "KNOW THYSELF" inscribed at the Temple of Apollo at Delphi.'
},
{
level: 3, cipher: 'Substitution', difficulty: 'Intermediate',
prompt: 'A monoalphabetic substitution with keyword CIPHER. Use frequency analysis or the keyword to crack it.',
ciphertext: 'SEPQETS BDHE DL NJCDL SDABT',
answer: 'SECRETS HIDE IN PLAIN SIGHT',
lesson: 'Monoalphabetic ciphers preserve letter frequency. The frequency counts are relabelled, not erased; E need not be the most common letter in a short message. AES combines nonlinear substitution with diffusion and key mixing over many rounds.',
hints: [
'The keyword CIPHER produces the alphabet: C I P H E R A B D F G J K L M N O Q S T U V W X Y Z. Map ciphertext back.',
'E encrypts to itself under this keyword alphabet. Use repeated patterns as clues; short-text frequencies are only a heuristic.'
],
walkthrough: 'Keyword CIPHER generates the substitution alphabet: C-I-P-H-E-R-A-B-D-F-G-J-K-L-M-N-O-Q-S-T-U-V-W-X-Y-Z. To decrypt, find each ciphertext letter\'s position in the cipher alphabet and map it to the standard alphabet position.'
},
{
level: 4, cipher: 'Vigenère', difficulty: 'Intermediate',
prompt: 'This message was encrypted with a Vigenère cipher. The key is a common English word related to waiting.',
ciphertext: 'IHX SIL KW EAMQIAEI',
answer: 'THE KEY IS PATIENCE',
lesson: 'A repeating Vigenère key creates periodic structure. Kasiski examination can suggest candidate periods from repeated sequences; with the period known, each position class is a Caesar substitution.',
hints: [
'The key relates to "waiting." Try PATIENCE as the key word.',
'Vigenère: subtract key letters from ciphertext letters mod 26. I-P=T, H-A=H, X-T=E… Align the key PATIENCE with letters only.'
],
walkthrough: 'The keyword is PATIENCE. Align it with the ciphertext letters (skipping spaces): I-P=T, H-A=H, X-T=E, S-I=K… Vigenère decryption: (ciphertext - key) mod 26 for each letter position.'
},
{
level: 5, cipher: 'Playfair', difficulty: 'Expert',
prompt: 'This Playfair-encrypted message uses the keyword MONARCHY. Decrypt the digraph pairs.',
ciphertext: 'ZD XL QR AP GA EQ LU MH IZ',
answer: 'TRUST NO SINGLE LOCK',
lesson: 'Playfair encrypts letter pairs (digraphs), making frequency analysis harder. But digraph frequencies still leak information — a large block size alone is not enough. Modern security also requires a suitable cipher, mode and key handling.',
hints: [
'Build the 5×5 Playfair grid with MONARCHY: M-O-N-A-R / C-H-Y-B-D / E-F-G-I-K / L-P-Q-S-T / U-V-W-X-Z',
'Apply the rectangle/row/column rules in reverse for each pair: ZD→TR, XL→US, etc.'
],
walkthrough: 'Grid: M-O-N-A-R / C-H-Y-B-D / E-F-G-I-K / L-P-Q-S-T / U-V-W-X-Z. To decrypt, reverse the Playfair rules: same row → shift left, same column → shift up, rectangle → swap corners. Process pairs: ZD, XL, QR, AP, GA, EQ, LU, MH, IZ.'
},
{
level: 6, cipher: 'Enigma', difficulty: 'Expert',
prompt: 'Enigma-encrypted with rotors I-II-III, reflector B, rings AAA, no plugboard, at starting position MCK. Type each letter to trace the signal.',
ciphertext: 'APZ LBTFZ OXPBB',
answer: 'THE BOMBE TURNS',
lesson: 'Enigma key-space counts depend on the model and permitted settings. Its reflector prevents self-encryption, a property codebreakers exploited. Even huge keyspaces fail if the algorithm has exploitable properties.',
hints: [
'Use the Enigma demo on the Enigma exhibit page with start position MCK.',
'Enigma is reciprocal: encrypting the ciphertext with the same settings produces the plaintext.'
],
walkthrough: 'Enigma is its own inverse — typing the ciphertext with the same rotor settings (I-II-III at MCK) produces the plaintext. The answer refers to the Bombe, the British electromechanical key-search machine developed from Turing’s design with Welchman’s diagonal-board improvement, building on earlier Polish work.'
}
];
/* ── New challenges (levels 7-10) ── */
CHALLENGES.push(
{
level: 7, cipher: 'ROT13', difficulty: 'Beginner',
prompt: 'ROT13 is a special case of Caesar where every letter shifts by exactly 13 positions. Since 13 is half of 26, applying it twice returns the original text.',
ciphertext: 'XABJYRQTR VF CBJRE',
answer: 'KNOWLEDGE IS POWER',
lesson: 'ROT13 is its own inverse — encrypting twice returns the original. Enigma has this property at a fixed rotor state. A general Feistel cipher instead decrypts by reversing the round-key order; it is not necessarily an involution.',
hints: [
'Shift every letter back (or forward) by 13 — both directions give the same result.',
'X→K, A→N, B→O, J→W, Y→L, R→E…'
],
walkthrough: 'ROT13 shifts each letter by 13: X(23)→K(10), A(0)→N(13), B(1)→O(14), J(9)→W(22)… Since 13+13=26, encrypting and decrypting are identical. The answer is Francis Bacon\'s aphorism "KNOWLEDGE IS POWER."'
},
{
level: 8, cipher: 'Columnar Transposition', difficulty: 'Expert',
prompt: 'The plaintext was written into rows under the key KEYS, then columns were read out in alphabetical key order. Reverse the process.',
ciphertext: 'RTOOBKCNAEEEHDW',
answer: 'BREAK THE CODE NOW',
lesson: 'Transposition rearranges positions while preserving letter counts. AES ShiftRows also permutes positions; MixColumns goes further by combining bytes algebraically.',
hints: [
'Key KEYS → 4 columns. Sorted alphabetically: E(col 2), K(col 1), S(col 4), Y(col 3). 15 letters ÷ 4 columns = 4 rows, last column short.',
'Distribute ciphertext into columns in key order — E gets 4 letters (RTOO), K gets 4 (BKCN), S gets 3 (AEE), Y gets 4 (EHDW). Write them back into grid positions and read rows.'
],
walkthrough: 'Key KEYS sorted = E(2nd), K(1st), S(4th), Y(3rd). Column E: RTOO → col 2. Column K: BKCN → col 1. Column S: AEE → col 4 (3 rows). Column Y: EHDW → col 3. Reading rows: B-R-E-A / K-T-H-E / C-O-D-E / N-O-W → "BREAK THE CODE NOW".'
},
{
level: 9, cipher: 'Multi-Layer', difficulty: 'Master',
prompt: 'This message was encrypted with two classical ciphers layered together. One reverses the alphabet, the other shifts it by a single-digit number. Recover the plaintext and find a compatible ordering and shift.',
ciphertext: 'RGNYCTEC ESTQMCPO GVV',
answer: 'PATIENCE CONQUERS ALL',
lesson: 'Layering two weak ciphers doesn\'t necessarily create a strong one — this particular Atbash-and-Caesar composition is still a monoalphabetic substitution. AES instead combines key addition, nonlinear substitution and diffusion over 10, 12 or 14 rounds.',
hints: [
'Two layers: one is Atbash (A↔Z reverse), the other is a Caesar shift (1–9). Try undoing the outer layer first for different shift values.',
'Outer layer: Caesar +7. Undo it first (shift back 7): R→K, G→Z, N→G, Y→R… → KZGRVMXV XLMJFVIH ZOO. Then undo Atbash on that result.'
],
walkthrough: 'Layer 1 (inner): Atbash reversal. Layer 2 (outer): Caesar shift +7. To decrypt: (1) Shift each letter back by 7 → KZGRVMXV XLMJFVIH ZOO. (2) Apply Atbash: K→P, Z→A, G→T, R→I, V→E, M→N, X→C, V→E → PATIENCE CONQUERS ALL.'
},
{
level: 10, cipher: 'Multi-Layer', difficulty: 'Master',
prompt: 'Two operations were applied: a letter shift and then the entire result was written backwards. Determine the shift value and undo both layers.',
ciphertext: 'DJPSJMYWJMUNHYXWNK',
answer: 'FIRST CIPHER THEN KEY',
lesson: 'Here a uniform Caesar shift and text reversal commute: either decryption order works. Operations do not commute in general; this example is a useful exception, not proof that reversing round operations preserves a modern cipher.',
hints: [
'The outer operation is reversal. Try reading the ciphertext backwards first, then apply Caesar shifts.',
'Reversed: KNWXYHNUMJWYMJSPJD. Now try small Caesar shifts backwards. Shift −5: K→F, N→I, W→R, X→S, Y→T…'
],
walkthrough: 'Step 1 — Reverse the ciphertext: DJPSJMYWJMUNHYXWNK → KNWXYHNUMJWYMJSPJD. Step 2 — Undo Caesar shift of 5: K(10)→F(5), N(13)→I(8), W(22)→R(17), X(23)→S(18), Y(24)→T(19)… → FIRSTCIPHERTHENKEY → "FIRST CIPHER THEN KEY".'
}
);
const STORAGE_KEY = 'cipher-museum-challenges';
function getState() {
try { return JSON.parse(localStorage.getItem(STORAGE_KEY)) || {}; } catch { return {}; }
}
function saveState(state) {
try { localStorage.setItem(STORAGE_KEY, JSON.stringify(state)); } catch {}
}
function normalize(s) {
return s.toUpperCase().replace(/[^A-Z]/g, '');
}
function updateProgress() {
const state = getState();
const solved = CHALLENGES.filter(c => state['ch' + c.level]).length;
const total = CHALLENGES.length;
document.getElementById('progress-text').textContent = solved + ' of ' + total + ' solved';
document.getElementById('progress-fill').style.width = ((solved / total) * 100) + '%';
if (solved === total) document.getElementById('congrats').classList.add('visible');
}
function renderChallenges() {
const container = document.getElementById('challenges-container');
const state = getState();
container.innerHTML = CHALLENGES.map(ch => {
const solved = state['ch' + ch.level];
const attempts = state['attempts' + ch.level] || 0;
const diffColor = {Beginner:'var(--green)',Intermediate:'var(--orange)',Expert:'var(--red)',Master:'var(--purple)'}[ch.difficulty] || 'var(--tx3)';
return `
<div class="ch-card ${solved ? 'solved' : ''}" data-level="${ch.level}">
<div class="ch-header">
<div class="ch-level">${solved ? '✓' : ch.level}</div>
<div class="ch-meta">
<h3>${ch.cipher}</h3>
<span style="color:${diffColor}">${ch.difficulty}</span>
</div>
</div>
<div class="ch-body">
<p class="ch-prompt">${ch.prompt}</p>
<div class="ch-ciphertext">${ch.ciphertext}</div>
${solved ? `<div class="ch-feedback correct" style="display:block">✓ Solved! Answer: ${ch.answer}</div>${ch.lesson ? `<div style="margin-top:.75rem;padding:.75rem;background:var(--gold-glow);border:1px solid var(--gold-b);border-radius:var(--r);font-size:.82rem;color:var(--tx2);line-height:1.7;"><strong style="color:var(--gold);font-size:.65rem;letter-spacing:.12em;text-transform:uppercase;display:block;margin-bottom:.3rem;">What this teaches</strong>${ch.lesson}</div>` : ''}` : `
<div class="ch-feedback" id="feedback-${ch.level}" role="alert" aria-live="assertive"></div>
<div class="ch-input-row">
<input class="ch-input" id="input-${ch.level}" type="text"
placeholder="Your answer…" aria-label="Decrypted answer for challenge ${ch.level}"
aria-describedby="feedback-${ch.level}"
autocomplete="off">
<button class="ch-submit" data-fn="checkAnswer" data-arg="${ch.level}">Submit</button>
</div>
<button class="ch-hint-btn" data-fn="showHint" data-arg="${ch.level}">💡 Hint ${attempts >= 3 ? '' : '(-1 pt)'}</button>
<div class="ch-hint" id="hint-${ch.level}" role="status" aria-live="polite"></div>
${attempts >= 3 ? `<div class="ch-walkthrough visible"><h4>Walkthrough</h4><p>${ch.walkthrough}</p></div>` : ''}
`}
</div>
</div>`;
}).join('');
updateProgress();
}
window.checkAnswer = function(level) {
const ch = CHALLENGES[level - 1];
const state = getState();
const input = document.getElementById('input-' + level);
const feedback = document.getElementById('feedback-' + level);
const guess = normalize(input.value);
const answer = normalize(ch.answer);
state['attempts' + level] = (state['attempts' + level] || 0) + 1;
if (guess === answer) {
state['ch' + level] = true;
feedback.className = 'ch-feedback correct';
feedback.textContent = '✓ Correct! ' + ch.answer;
saveState(state);
setTimeout(renderChallenges, 800);
} else {
feedback.className = 'ch-feedback wrong';
feedback.textContent = '✗ Not quite — check your work and try again.' + (state['attempts' + level] >= 3 ? ' Walkthrough unlocked below.' : ' Use a hint if you\'re stuck.');
saveState(state);
if (state['attempts' + level] >= 3) renderChallenges();
}
};
window.showHint = function(level) {
const ch = CHALLENGES[level - 1];
const state = getState();
const hintDiv = document.getElementById('hint-' + level);
const hintIdx = state['hintIdx' + level] || 0;
if (hintIdx < ch.hints.length) {
hintDiv.textContent = ch.hints[hintIdx];
hintDiv.classList.add('visible');
state['hintIdx' + level] = hintIdx + 1;
saveState(state);
}
};
// Enter key submits
document.addEventListener('keydown', function(e) {
if (e.key === 'Enter' && e.target.classList.contains('ch-input')) {
const level = parseInt(e.target.id.replace('input-', ''));
if (level) window.checkAnswer(level);
}
});
// Copy a Wordle-style shareable summary of progress
document.getElementById('share-progress').addEventListener('click', () => {
const state = getState();
const squares = CHALLENGES.map(c => state['ch' + c.level] ? '🟩' : '⬛').join('');
const solved = CHALLENGES.filter(c => state['ch' + c.level]).length;
const text = '🔐 The Cipher Museum — Challenges ' + solved + '/' + CHALLENGES.length +
'\n' + squares + '\nhttps://ciphermuseum.com/challenges.html';
const status = document.getElementById('share-status');
const done = () => {
status.textContent = 'Copied!';
setTimeout(() => { status.textContent = ''; }, 2500);
};
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(done, () => { status.textContent = text; });
} else {
const ta = document.createElement('textarea');
ta.value = text;
document.body.appendChild(ta);
ta.select();
try { document.execCommand('copy'); done(); } catch { status.textContent = text; }
ta.remove();
}
});
renderChallenges();
})();
</script>
<script src="js/nav.js" defer></script>
<script src="js/lightbox.js"></script>
</body>
</html>