-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed-phrase-entropy.html
More file actions
638 lines (594 loc) · 20.4 KB
/
seed-phrase-entropy.html
File metadata and controls
638 lines (594 loc) · 20.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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seed Phrase Entropy - DeFi Visualized</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
color: #e4e4e4;
min-height: 100vh;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
color: #00d9ff;
margin-bottom: 8px;
}
.subtitle {
text-align: center;
color: #888;
margin-bottom: 30px;
max-width: 600px;
margin-left: auto;
margin-right: auto;
}
.container {
max-width: 900px;
margin: 0 auto;
}
.card {
background: rgba(255, 255, 255, 0.05);
border-radius: 16px;
padding: 24px;
border: 1px solid rgba(255, 255, 255, 0.1);
margin-bottom: 20px;
}
.slots-container {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
margin-bottom: 24px;
}
@media (max-width: 600px) {
.slots-container {
grid-template-columns: repeat(3, 1fr);
}
}
.slot {
background: rgba(0, 0, 0, 0.3);
border-radius: 8px;
padding: 12px 8px;
text-align: center;
position: relative;
overflow: hidden;
height: 70px;
display: flex;
flex-direction: column;
justify-content: center;
}
.slot.active {
border: 2px solid #00d9ff;
box-shadow: 0 0 20px rgba(0, 217, 255, 0.3);
}
.slot.filled {
border: 2px solid #51cf66;
}
.slot.empty {
border: 2px solid #444;
}
.slot-number {
font-size: 10px;
color: #666;
position: absolute;
top: 4px;
left: 8px;
}
.slot-word {
font-size: 14px;
font-weight: 600;
color: #fff;
height: 24px;
overflow: hidden;
}
.slot.spinning .slot-word {
animation: spin 0.1s linear infinite;
}
@keyframes spin {
0% { transform: translateY(-100%); opacity: 0; }
50% { transform: translateY(0); opacity: 1; }
100% { transform: translateY(100%); opacity: 0; }
}
.slot-choices {
font-size: 11px;
color: #888;
margin-top: 4px;
}
.slot.checksum {
border-color: #ff9f43;
}
.slot.checksum .slot-number {
color: #ff9f43;
}
.slot.checksum.filled {
border-color: #ff9f43;
}
.controls {
display: flex;
gap: 12px;
justify-content: center;
margin-bottom: 24px;
}
button {
padding: 14px 32px;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: transform 0.1s, opacity 0.1s;
}
button:hover {
transform: scale(1.02);
}
button:active {
transform: scale(0.98);
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
.btn-primary {
background: linear-gradient(135deg, #00d9ff, #00b8d9);
color: #000;
}
.btn-secondary {
background: rgba(255, 255, 255, 0.1);
color: #fff;
}
.total-section {
text-align: center;
padding: 24px;
background: rgba(0, 217, 255, 0.1);
border-radius: 12px;
margin-bottom: 24px;
}
.total-label {
font-size: 14px;
color: #888;
margin-bottom: 8px;
}
.total-value {
font-size: 28px;
font-weight: bold;
color: #00d9ff;
word-break: break-all;
font-family: 'Courier New', monospace;
}
.total-scientific {
font-size: 18px;
color: #888;
margin-top: 8px;
}
.formula {
font-family: 'Courier New', monospace;
color: #ff9f43;
font-size: 16px;
margin-bottom: 12px;
}
.comparisons {
display: flex;
flex-direction: column;
gap: 12px;
}
.comparison {
display: flex;
align-items: center;
gap: 16px;
padding: 16px;
background: rgba(0, 0, 0, 0.2);
border-radius: 8px;
}
.comparison-icon {
font-size: 28px;
width: 50px;
text-align: center;
}
.comparison-info {
flex: 1;
}
.comparison-name {
font-size: 14px;
color: #e4e4e4;
margin-bottom: 4px;
}
.comparison-value {
font-size: 13px;
color: #888;
font-family: 'Courier New', monospace;
}
.comparison-bar-container {
width: 120px;
height: 8px;
background: #333;
border-radius: 4px;
overflow: hidden;
}
.comparison-bar {
height: 100%;
background: linear-gradient(90deg, #51cf66, #00d9ff);
border-radius: 4px;
transition: width 0.5s;
}
.comparison.exceeded .comparison-bar {
background: linear-gradient(90deg, #00d9ff, #ff9f43);
}
.comparison.exceeded .comparison-name {
color: #51cf66;
}
.time-section {
text-align: center;
padding: 20px;
background: rgba(255, 107, 107, 0.1);
border-radius: 12px;
border: 1px solid rgba(255, 107, 107, 0.3);
}
.time-label {
font-size: 14px;
color: #888;
margin-bottom: 8px;
}
.time-value {
font-size: 24px;
font-weight: bold;
color: #ff6b6b;
}
.time-note {
font-size: 12px;
color: #666;
margin-top: 8px;
}
.disclaimer {
font-size: 13px;
color: #666;
line-height: 1.6;
}
.disclaimer-title {
font-size: 12px;
color: #888;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 12px;
display: flex;
align-items: center;
gap: 8px;
}
.disclaimer ul {
margin: 0;
padding-left: 20px;
}
.disclaimer li {
margin-bottom: 8px;
}
.disclaimer strong {
color: #999;
}
.section-title {
font-size: 14px;
color: #888;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 8px;
text-align: center;
}
.scale-note {
font-size: 12px;
color: #666;
text-align: center;
margin-bottom: 16px;
}
.word-toggle {
display: flex;
justify-content: center;
gap: 8px;
margin-bottom: 20px;
}
.word-toggle button {
padding: 8px 20px;
border: 2px solid #444;
border-radius: 8px;
background: transparent;
color: #888;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.15s;
}
.word-toggle button.active {
border-color: #00d9ff;
color: #00d9ff;
background: rgba(0, 217, 255, 0.1);
}
.word-toggle button:hover:not(.active) {
border-color: #666;
}
</style>
</head>
<body>
<div class="container">
<a href="index.html" style="color: #00d9ff; text-decoration: none; font-size: 18px; display: inline-block; margin-bottom: 8px;" title="Home">
🏠
</a>
<h1>Seed Phrase Entropy</h1>
<p class="subtitle" id="subtitle">Why nobody can guess your seed phrase — the numbers are astronomical</p>
<div class="card">
<div class="word-toggle">
<button id="btn12" class="active" onclick="setWordCount(12)">12 Words</button>
<button id="btn24" onclick="setWordCount(24)">24 Words</button>
</div>
<div class="section-title" id="sectionTitle">BIP39 Seed Phrase (11 words + checksum)</div>
<div class="slots-container" id="slots"></div>
<div class="controls">
<button class="btn-primary" id="spinBtn" onclick="spinNext()">Pick Word #1</button>
<button class="btn-secondary" id="skipBtn" onclick="skipToEnd()">Skip to End</button>
<button class="btn-secondary" onclick="reset()">Reset</button>
</div>
</div>
<div class="card">
<div class="total-section">
<div class="total-label">Total Possible Combinations</div>
<div class="formula" id="formula">2048 choices per word (128 for checksum)</div>
<div class="total-value" id="totalValue">1</div>
<div class="total-scientific" id="totalScientific"></div>
</div>
</div>
<div class="card">
<div class="section-title">How Big Is This Number?</div>
<div class="scale-note">Progress bars use a logarithmic scale to visualize exponential growth</div>
<div class="comparisons" id="comparisons"></div>
</div>
<div class="card">
<div class="time-section">
<div class="time-label">Time to try all combinations at 1 trillion guesses/second</div>
<div class="time-value" id="timeValue">0 seconds</div>
<div class="time-note" id="timeNote">Easily crackable — keep adding words!</div>
</div>
</div>
<div class="card disclaimer">
<div class="disclaimer-title">ℹ️ Simplifications</div>
<p style="margin: 0 0 12px 0;">This is an educational visualization, not a technical specification. Some details are simplified:</p>
<ul>
<li><strong>Word selection:</strong> Real BIP39 generates random entropy bits first, then encodes them as words — not picked one-by-one like a slot machine.</li>
<li><strong>Brute force time:</strong> Doesn't account for current limitations (key derivation) nor future quantum breakthroughs — real attacks are much slower today, but quantum computing is a factor to prepare for.</li>
<li><strong>Passphrase:</strong> BIP39 supports an optional passphrase ("25th word") for additional security, not shown here.</li>
<li><strong>Blockchain variations:</strong> Different blockchains may have different implementations — some don't use a checksum word, others use different word lists or derivation paths.</li>
</ul>
</div>
</div>
<script>
const BIP39_WORDS = 2048;
let totalWords = 12;
// Checksum choices: 12 words = 128 (7 bits free), 24 words = 8 (3 bits free)
const CHECKSUM_MAP = { 12: 128, 24: 8 };
const ENTROPY_BITS = { 12: 128, 24: 256 };
// Sample BIP39 words for animation (distributed across alphabet)
const sampleWords = [
'abandon', 'apple', 'arena', 'bachelor', 'banana', 'blade', 'bright', 'bronze',
'camera', 'carbon', 'castle', 'chair', 'cherry', 'cloud', 'cobra', 'cruise',
'damage', 'dawn', 'desert', 'diamond', 'dolphin', 'dragon', 'dream', 'drift',
'eagle', 'earth', 'elder', 'electric', 'element', 'embark', 'energy', 'engine',
'fabric', 'falcon', 'family', 'fashion', 'film', 'flame', 'flower', 'forest',
'galaxy', 'garage', 'garden', 'genius', 'ghost', 'ginger', 'globe', 'gravity',
'hammer', 'harbor', 'harvest', 'helmet', 'hidden', 'hockey', 'horizon', 'hybrid',
'impact', 'import', 'infant', 'initial', 'insect', 'iron', 'island', 'ivory',
'jacket', 'jaguar', 'jazz', 'jelly', 'jewel', 'journey', 'jungle', 'junior',
'kangaroo', 'kernel', 'kingdom', 'kitchen', 'kiwi', 'knife', 'knight', 'koala',
'label', 'ladder', 'lamp', 'laptop', 'lemon', 'leopard', 'liberty', 'lunar',
'machine', 'magnet', 'mammal', 'mango', 'marble', 'meadow', 'monkey', 'mountain',
'napkin', 'narrow', 'nature', 'neck', 'neutral', 'night', 'noble', 'north',
'oasis', 'object', 'ocean', 'olive', 'onion', 'opera', 'orange', 'orbit',
'paddle', 'palace', 'panda', 'paper', 'peace', 'piano', 'pilot', 'planet',
'quantum', 'queen', 'question', 'quick', 'quiz', 'quote', 'rabbit', 'radar',
'saddle', 'salmon', 'saturn', 'scout', 'shadow', 'silver', 'solar', 'spirit',
'table', 'talent', 'taxi', 'temple', 'tiger', 'timber', 'tornado', 'trophy',
'umbrella', 'uncle', 'uniform', 'unique', 'universe', 'upgrade', 'urban', 'useful',
'vacuum', 'valley', 'vanilla', 'vapor', 'velvet', 'village', 'vintage', 'violin',
'waffle', 'wallet', 'warrior', 'wealth', 'whale', 'winter', 'wisdom', 'wolf',
'yellow', 'yoga', 'young', 'zebra', 'zero', 'zone', 'abandon', 'zoo'
];
const comparisons = [
{ icon: '🏖️', name: 'Grains of sand on Earth', value: 7.5e18, exp: '7.5 × 10¹⁸' },
{ icon: '💧', name: 'Drops of water in all oceans', value: 2e25, exp: '2 × 10²⁵' },
{ icon: '⭐', name: 'Stars in observable universe', value: 1e24, exp: '10²⁴' },
{ icon: '🌍', name: 'Atoms on planet Earth', value: 1e50, exp: '10⁵⁰' },
{ icon: '🌌', name: 'Atoms in observable universe', value: 1e80, exp: '10⁸⁰' },
];
let currentWord = 0;
let isSpinning = false;
let spinInterval = null;
let totalCombinations = 1n;
function init() {
const slotsContainer = document.getElementById('slots');
slotsContainer.innerHTML = '';
for (let i = 0; i < totalWords; i++) {
const slot = document.createElement('div');
const isChecksum = i === totalWords - 1;
slot.className = 'slot empty' + (isChecksum ? ' checksum' : '');
slot.id = `slot-${i}`;
slot.innerHTML = `
<div class="slot-number">${isChecksum ? 'checksum' : '#' + (i + 1)}</div>
<div class="slot-word">—</div>
<div class="slot-choices"></div>
`;
slotsContainer.appendChild(slot);
}
// Update section title
document.getElementById('sectionTitle').textContent =
`BIP39 Seed Phrase (${totalWords - 1} words + checksum)`;
renderComparisons();
updateDisplay();
}
function setWordCount(count) {
totalWords = count;
document.getElementById('btn12').classList.toggle('active', count === 12);
document.getElementById('btn24').classList.toggle('active', count === 24);
reset();
}
function renderComparisons() {
const container = document.getElementById('comparisons');
container.innerHTML = comparisons.map((c, i) => `
<div class="comparison" id="comparison-${i}">
<div class="comparison-icon">${c.icon}</div>
<div class="comparison-info">
<div class="comparison-name">${c.name}</div>
<div class="comparison-value">${c.exp}</div>
</div>
<div class="comparison-bar-container">
<div class="comparison-bar" id="bar-${i}" style="width: 0%"></div>
</div>
</div>
`).join('');
}
function getRandomWord() {
return sampleWords[Math.floor(Math.random() * sampleWords.length)];
}
function formatBigInt(n) {
const str = n.toString();
if (str.length <= 12) {
return str.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
return str;
}
function toScientific(n) {
const str = n.toString();
const exp = str.length - 1;
if (exp < 6) return '';
const mantissa = str[0] + '.' + str.slice(1, 3);
return `≈ ${mantissa} × 10^${exp}`;
}
function updateDisplay() {
document.getElementById('totalValue').textContent = formatBigInt(totalCombinations);
document.getElementById('totalScientific').textContent = toScientific(totalCombinations);
// Update formula
const checksumChoices = CHECKSUM_MAP[totalWords];
const entropyBits = ENTROPY_BITS[totalWords];
const normalWords = totalWords - 1;
if (currentWord === 0) {
document.getElementById('formula').textContent = `2048 choices per word (${checksumChoices} for checksum)`;
} else if (currentWord < normalWords) {
document.getElementById('formula').textContent = `2048^${currentWord}`;
} else if (currentWord === normalWords) {
document.getElementById('formula').textContent = `2048^${normalWords}`;
} else {
document.getElementById('formula').textContent = `2048^${normalWords} × ${checksumChoices} = 2^${entropyBits}`;
}
// Update comparisons
const totalFloat = Number(totalCombinations);
comparisons.forEach((c, i) => {
const bar = document.getElementById(`bar-${i}`);
const comparison = document.getElementById(`comparison-${i}`);
const ratio = Math.min(100, (Math.log10(totalFloat) / Math.log10(c.value)) * 100);
bar.style.width = `${ratio}%`;
comparison.classList.toggle('exceeded', totalFloat >= c.value);
});
// Update time
const guessesPerSecond = 1e12; // 1 trillion
const secondsNeeded = totalFloat / guessesPerSecond;
const timeStr = formatTime(secondsNeeded);
document.getElementById('timeValue').textContent = timeStr;
// Update time note based on difficulty
const timeNote = document.getElementById('timeNote');
const years = secondsNeeded / 31536000;
if (secondsNeeded < 3600) { // less than an hour
timeNote.textContent = 'Easily crackable — keep adding words!';
} else if (secondsNeeded < 31536000) { // less than a year
timeNote.textContent = 'Getting harder, but still vulnerable';
} else if (years < 1e9) { // less than a billion years
timeNote.textContent = 'Impractical to crack';
} else {
timeNote.textContent = 'Even with all computers on Earth combined, this is impossible';
}
// Update buttons
const btn = document.getElementById('spinBtn');
const skipBtn = document.getElementById('skipBtn');
if (currentWord >= totalWords) {
btn.disabled = true;
btn.textContent = 'Complete!';
skipBtn.disabled = true;
} else {
btn.disabled = false;
skipBtn.disabled = false;
const isLastWord = currentWord === totalWords - 1;
btn.textContent = isLastWord ? 'Pick Checksum' : `Pick Word #${currentWord + 1}`;
}
}
function formatTime(seconds) {
if (seconds < 1) return 'instant';
if (seconds < 60) return `${seconds.toFixed(0)} seconds`;
if (seconds < 3600) return `${(seconds / 60).toFixed(0)} minutes`;
if (seconds < 86400) return `${(seconds / 3600).toFixed(0)} hours`;
if (seconds < 31536000) return `${(seconds / 86400).toFixed(0)} days`;
const years = seconds / 31536000;
if (years < 1e6) return `${years.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ',')} years`;
if (years < 1e9) return `${(years / 1e6).toFixed(1)} million years`;
if (years < 1e12) return `${(years / 1e9).toFixed(1)} billion years`;
if (years < 1e15) return `${(years / 1e12).toFixed(1)} trillion years`;
const exp = Math.floor(Math.log10(years));
const mantissa = (years / Math.pow(10, exp)).toFixed(1);
return `${mantissa} × 10^${exp} years`;
}
function spinNext() {
if (isSpinning || currentWord >= totalWords) return;
isSpinning = true;
const slot = document.getElementById(`slot-${currentWord}`);
slot.className = 'slot active spinning';
const wordEl = slot.querySelector('.slot-word');
let spins = 0;
const maxSpins = 20 + Math.random() * 10;
spinInterval = setInterval(() => {
wordEl.textContent = getRandomWord();
spins++;
if (spins >= maxSpins) {
clearInterval(spinInterval);
finishSpin(slot, wordEl);
}
}, 80);
}
function finishSpin(slot, wordEl) {
const finalWord = getRandomWord();
wordEl.textContent = finalWord;
const isChecksum = currentWord === totalWords - 1;
slot.className = 'slot filled' + (isChecksum ? ' checksum' : '');
const choicesEl = slot.querySelector('.slot-choices');
const choices = isChecksum ? CHECKSUM_MAP[totalWords] : BIP39_WORDS;
choicesEl.textContent = `1 of ${choices}`;
totalCombinations = totalCombinations * BigInt(choices);
currentWord++;
isSpinning = false;
updateDisplay();
}
function skipToEnd() {
if (isSpinning) return;
while (currentWord < totalWords) {
const slot = document.getElementById(`slot-${currentWord}`);
const wordEl = slot.querySelector('.slot-word');
const choicesEl = slot.querySelector('.slot-choices');
const isChecksum = currentWord === totalWords - 1;
wordEl.textContent = getRandomWord();
slot.className = 'slot filled' + (isChecksum ? ' checksum' : '');
const choices = isChecksum ? CHECKSUM_MAP[totalWords] : BIP39_WORDS;
choicesEl.textContent = `1 of ${choices}`;
totalCombinations = totalCombinations * BigInt(choices);
currentWord++;
}
updateDisplay();
}
function reset() {
if (spinInterval) clearInterval(spinInterval);
currentWord = 0;
isSpinning = false;
totalCombinations = 1n;
init();
}
// Initialize
init();
</script>
</body>
</html>