-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenges.html
More file actions
402 lines (380 loc) · 24.4 KB
/
challenges.html
File metadata and controls
402 lines (380 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
<!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. Six 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. Six progressively harder challenges — from Caesar to Enigma.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://ciphermuseum.com/challenges.html">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Cipher Challenges — The Cipher Museum">
<meta name="twitter:description" content="Break real ciphers. Six progressively harder challenges — from Caesar to Enigma.">
<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="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-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="index.html">Entrance</a></li>
<li><a href="museum-map.html">Museum Map</a></li>
<li><a href="timeline.html">Timeline</a></li>
<li><a href="challenges.html" class="active">Challenges</a></li>
<li><a href="glossary.html">Glossary</a></li>
<li><a href="cryptanalysis.html">Cryptanalysis Techniques</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>
</div>
<div class="challenges-grid" id="challenges-container"></div>
<div class="ch-congrats" id="congrats">
<h2>🏆 Master Codebreaker</h2>
<p>You've broken every cipher in the museum. 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;">From Caesar to multi-layered systems, every cipher tells the same story: security through obscurity never lasts. Only mathematics endures.</p>
</div>
</section>
</main>
<footer class="museum-footer">
<div class="footer-grid">
<div class="footer-brand">
<span class="footer-logo-text">The Cipher Museum</span>
<p class="footer-brand-desc">Open-source cryptography education. MIT License. GitHub Pages.</p>
</div>
<div>
<div class="footer-col-title">Navigate</div>
<ul class="footer-links">
<li><a href="museum-map.html">Museum Map</a></li>
<li><a href="timeline.html">Timeline</a></li>
<li><a href="cryptanalysis.html">Cryptanalysis Techniques</a></li>
<li><a href="modern.html">Modern Crypto</a></li>
</ul>
</div>
<div>
<div class="footer-col-title">Explore</div>
<ul class="footer-links">
<li><a href="halls/ancient.html">Hall I: Ancient</a></li>
<li><a href="halls/machines.html">Hall VI: Machines</a></li>
<li><a href="halls/unbreakable.html">Final Hall</a></li>
</ul>
</div>
</div>
<div class="footer-bottom">
<span class="footer-copy">© The Cipher Museum · MIT License</span>
<span class="footer-copy">Cipher Challenges</span>
</div>
</footer>
<script src="js/ciphers/all-engines.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 possible keys — you can try them all in seconds. 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 the original Latin quote 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. Security through obscurity never works.',
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: 'SHFRHS JPGH PL MDCPL SPIJT',
answer: 'SECRETS HIDE IN PLAIN SIGHT',
lesson: 'Monoalphabetic ciphers preserve letter frequency. The letter E still appears most often — just under a different name. This is why AES uses non-linear S-boxes.',
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.',
'S→S? No — S is the 19th letter. In the cipher alphabet, position 19 = S maps to original S. Check: position for P in cipher = 3rd letter, which maps to original C… work through the mapping.'
],
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: 'IAS DGC XH JTIGGTQW',
answer: 'THE KEY IS PATIENCE',
lesson: 'Vigenère defeated frequency analysis for 300 years by using multiple alphabets. But the repeating key creates patterns — Kasiski examination finds the key length, then each position reduces to Caesar.',
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, A-A=A..? Try aligning the key PATIENCE with letters only.'
],
walkthrough: 'The keyword is PATIENCE. Align it with the ciphertext letters (skipping spaces): I-P=T, A-A=H, S-T=E, D-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: 'SQBRLG MK RDHAFM FKEE',
answer: 'TRUST NO SINGLE LOCK',
lesson: 'Playfair encrypts letter pairs (digraphs), making frequency analysis harder. But digraph frequencies still leak information — modern block ciphers use 128-bit blocks to eliminate this.',
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: SQ→TR, BR→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: SQ, BR, LG, MK, RD, HA, FM, FK, EE.'
},
{
level: 6, cipher: 'Enigma', difficulty: 'Expert',
prompt: 'Enigma-encrypted with rotors I-II-III at starting position MCK. Type each letter to trace the signal.',
ciphertext: 'YPR CTYWK DSJWH',
answer: 'THE BOMBE TURNS',
lesson: 'Enigma had 158 quintillion settings but structural flaws (no letter encrypts to itself) gave codebreakers a foothold. 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 electromechanical machine Alan Turing designed to crack Enigma at Bletchley Park.'
}
];
/* ── 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. This "involution" property also exists in Enigma and modern Feistel networks.',
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 ciphers rearrange letters without changing them — providing diffusion but no confusion. AES ShiftRows and MixColumns are the modern descendants.',
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. Determine both operations and their order.',
ciphertext: 'RGNYCTEC ESTQMCPO GVV',
answer: 'PATIENCE CONQUERS ALL',
lesson: 'Layering two weak ciphers doesn\'t necessarily create a strong one — if each layer is independently attackable, the stack falls. Modern ciphers use 10-14 rounds where each round depends on the previous one.',
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 in the correct order.',
ciphertext: 'DJPSJMYWJMUNHYXWNK',
answer: 'FIRST CIPHER THEN KEY',
lesson: 'Order of operations matters. In modern cryptography, the precise sequence of substitution, permutation, and key mixing in each round is what creates security. Scramble the order and the cipher breaks.',
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" onclick="checkAnswer(${ch.level})">Submit</button>
</div>
<button class="ch-hint-btn" onclick="showHint(${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);
}
});
renderChallenges();
})();
</script>
<script src="js/nav.js" defer></script>
<script src="js/lightbox.js"></script>
</body>
</html>