Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
1507 lines (1362 loc) · 67.5 KB
/
Copy pathindex.html
File metadata and controls
1507 lines (1362 loc) · 67.5 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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bitpolito Cryptography Simulator</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>%F0%9F%93%8B</text></svg>">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css?v=2.0">
<style>
/* Critical Header Navigation Tab Styling (Photo 2 Floating Pills) */
.nav-tabs-group {
display: flex !important;
align-items: center !important;
gap: 10px !important;
}
.nav-tab-btn {
background: #FFFFFF !important;
color: #001CE0 !important;
box-shadow: 0 16px 36px -6px rgba(0, 0, 0, 0.08), 0 6px 16px -2px rgba(0, 0, 0, 0.03) !important;
border: 1px solid rgba(0, 0, 0, 0.03) !important;
border-radius: 9999px !important;
padding: 8px 18px !important;
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
font-size: 13px !important;
font-weight: 700 !important;
letter-spacing: -0.2px !important;
cursor: pointer !important;
display: inline-flex !important;
align-items: center !important;
justify-content: center !important;
gap: 8px !important;
transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1) !important;
outline: none !important;
text-decoration: none !important;
white-space: nowrap !important;
}
.nav-tab-btn:hover {
transform: translateY(-2px) !important;
color: #0016B8 !important;
box-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.12), 0 8px 18px -2px rgba(0, 0, 0, 0.05) !important;
}
.nav-tab-btn.active {
background: #001CE0 !important;
color: #FFFFFF !important;
border: 1px solid #001CE0 !important;
box-shadow: 0 16px 36px -6px rgba(0, 28, 224, 0.35), 0 6px 14px -2px rgba(0, 28, 224, 0.2) !important;
}
</style>
</head>
<body>
<!-- Dynamic SVG Connector Canvas for lines connecting envelope to sender -->
<svg id="connector-svg">
<path id="connector-path" d="" fill="none" stroke="#001CE0" stroke-width="2.5" stroke-dasharray="6,6" stroke-linecap="round" />
<circle id="connector-start-dot" cx="0" cy="0" r="5" fill="#001CE0" style="display:none;" />
<circle id="connector-end-dot" cx="0" cy="0" r="5" fill="#001CE0" style="display:none;" />
</svg>
<!-- Top App Navigation -->
<header class="app-header">
<div class="logo-area">
<div class="pill-badge">
<span class="dot"></span>
<span>Bitpolito secp256k1</span>
</div>
<div class="header-title-group">
<h1>Bitpolito Cryptography Simulator</h1>
<p>Interactive Public Key Encryption & Elliptic Curve Mathematics</p>
</div>
</div>
<div class="header-actions">
<!-- Header Tabs Navigation Group -->
<nav class="nav-tabs-group" role="tablist" aria-label="Main Navigation">
<button class="photo2-pill-btn small nav-tab-btn active" id="tab-nav-sim" onclick="switchView('simulator')">
<span>Simulator</span>
</button>
<button class="photo2-pill-btn small nav-tab-btn" id="nav-guide-btn" onclick="switchView('graph')">
<span>Cryptography Guide</span>
</button>
<button class="photo2-pill-btn small nav-tab-btn" id="tab-nav-address" onclick="switchView('address')">
<span>Point to Address</span>
</button>
<button class="photo2-pill-btn small nav-tab-btn" id="tab-nav-merkle" onclick="switchView('merkle')">
<span>Merkle Tree</span>
</button>
</nav>
<button id="sound-toggle-btn" class="photo2-pill-btn small" onclick="toggleSound()">
Sound: ON
</button>
</div>
</header>
<!-- Equation Banner -->
<div class="formula-pill-banner" onclick="switchView('graph')" title="Click to open interactive 2D curve graph">
<span class="formula-tag">Bitcoin Curve</span>
<span>Elliptic Formula:</span>
<span class="formula-math">y² ≡ x³ + 7 (mod p)</span>
<span style="color:var(--text-dim); margin:0 4px;">•</span>
<span>Public Key:</span>
<span class="formula-math">Q = d · G</span>
</div>
<!-- Main View 1: Central Simulator Stage (Alice & Bob) -->
<main class="simulator-stage" id="view-simulator">
<div class="characters-stage-container">
<!-- Alice Character Unit (Left) -->
<section class="character-unit" id="alice-unit">
<!-- Pixel Avatar Frame (Right-clickable) -->
<div class="avatar-frame" id="alice-avatar-frame" title="Right-click Alice to send encrypted message">
<div class="avatar-halo"></div>
<!-- Exact Pixel Art from Image 1: Female hair icon (10x10) -->
<svg class="pixel-avatar-svg" viewBox="0 0 10 10" shape-rendering="crispEdges">
<!-- Row 0 -->
<rect x="3" y="0" width="4" height="1" fill="#001ce0" />
<!-- Row 1 -->
<rect x="2" y="1" width="4" height="1" fill="#001ce0" />
<rect x="7" y="1" width="1" height="1" fill="#001ce0" />
<!-- Row 2 -->
<rect x="2" y="2" width="3" height="1" fill="#001ce0" />
<rect x="6" y="2" width="2" height="1" fill="#001ce0" />
<!-- Row 3 -->
<rect x="1" y="3" width="3" height="1" fill="#001ce0" />
<rect x="7" y="3" width="2" height="1" fill="#001ce0" />
<!-- Row 4 -->
<rect x="1" y="4" width="2" height="1" fill="#001ce0" />
<rect x="7" y="4" width="2" height="1" fill="#001ce0" />
<!-- Row 5 -->
<rect x="0" y="5" width="3" height="1" fill="#001ce0" />
<rect x="7" y="5" width="3" height="1" fill="#001ce0" />
<!-- Row 6 -->
<rect x="0" y="6" width="4" height="1" fill="#001ce0" />
<rect x="6" y="6" width="4" height="1" fill="#001ce0" />
<!-- Row 7 -->
<rect x="4" y="7" width="2" height="1" fill="#001ce0" />
<!-- Row 8 -->
<rect x="2" y="8" width="2" height="1" fill="#001ce0" />
<rect x="6" y="8" width="2" height="1" fill="#001ce0" />
<!-- Row 9 -->
<rect x="0" y="9" width="10" height="1" fill="#001ce0" />
</svg>
</div>
<!-- Name in Bold Blue matching reference -->
<h2 class="character-name">ALICE</h2>
<!-- Keycard Box with Photo 2 Shadowing and Style -->
<div class="character-keycard">
<!-- Public Key Field -->
<div class="key-group">
<div class="key-label-row">
<span class="key-label-title">
<span>Public Key</span>
<span class="key-badge">Q = d · G</span>
</span>
<span style="font-size:10px; color:var(--text-dim);">secp256k1</span>
</div>
<div class="key-field-pill">
<span class="key-value-text" id="alice-pubkey">Loading...</span>
<div class="key-actions-group">
<button class="key-btn" onclick="copyText(document.getElementById('alice-pubkey').textContent, 'Alice Public Key')" title="Copy Public Key">
📋
</button>
</div>
</div>
</div>
<!-- Secret Private Key Field (Asterisk Masked with SVG Reveal Eye) -->
<div class="key-group">
<div class="key-label-row">
<span class="key-label-title">
<span>Secret Private Key</span>
<span class="key-badge">d ∈ [1, n-1]</span>
</span>
<span style="font-size:10px; color:var(--text-dim);">256-bit</span>
</div>
<div class="key-field-pill">
<span class="key-value-text masked" id="alice-privkey">••••••••••••••••••••••••••••••••••••••••••••••••</span>
<div class="key-actions-group">
<!-- Clean SVG Reveal Eye Button -->
<button class="key-btn" id="alice-eye-btn" title="Toggle private key visibility">
<svg class="eye-svg" viewBox="0 0 24 24">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
<circle cx="12" cy="12" r="3"></circle>
</svg>
</button>
<button class="key-btn" onclick="copyText(state.alice.privateKeyHex, 'Alice Private Key')" title="Copy Private Key">
📋
</button>
</div>
</div>
</div>
<!-- Action Buttons -->
<div class="card-bottom-actions">
<button class="photo2-pill-btn primary" onclick="openComposeDialog('ALICE')">
<span>Send Encrypted Message</span>
</button>
<div class="hint-pill">Right-click <b>Alice</b> to open context menu</div>
</div>
</div>
<!-- Alice Incoming Messages Container -->
<div id="alice-incoming-container" class="incoming-container"></div>
</section>
<!-- Center Interaction Area (NO Popup, NO Blur, 100% Inline!) -->
<div class="central-stage-column">
<!-- Transmission Wire Track -->
<div class="transmission-lane">
<div class="wire-line-track"></div>
<div class="wire-badge" id="wire-transit-badge">
<span>Public Wire: Eavesdropper (Eve) only sees scrambled ciphertext</span>
</div>
</div>
<!-- Inline Messaging Stage: Box 1 (Compose) & Box 2 (Encrypted) -->
<div id="inline-messaging-stage" class="inline-messaging-stage" style="display: none;">
<!-- Box 1: Compose Box (Photo 2 Styling with Dynamic Envelope Badge) -->
<div class="photo2-dialog-box" id="compose-box">
<!-- Dynamic Message Icon connected to sender via line representing envelope -->
<div class="dialog-envelope-badge" id="compose-envelope-badge">
<span id="compose-sender-badge">
Envelope from <b>ALICE</b>
</span>
</div>
<div class="dialog-header">
<div class="dialog-title-group">
<h3>Compose Encrypted Message</h3>
<p>Bitcoin secp256k1 Asymmetric Cryptography</p>
</div>
<button class="close-btn" onclick="closeComposeDialog()" title="Close">✕</button>
</div>
<div class="compose-parts-container">
<!-- Part 1: Plaintext Message Input -->
<div class="compose-part-card">
<label class="part-label" for="compose-message-input">
<span>Part 1: Plaintext Message</span>
</label>
<textarea
id="compose-message-input"
class="message-textarea"
placeholder="Type your secret message here..."
></textarea>
<div class="quick-chips-row">
<span class="quick-chip" onclick="setQuickMessage('Secret Bitcoin seed: 5 BTC transfer authorized')">Bitcoin Seed</span>
<span class="quick-chip" onclick="setQuickMessage('Meet me at the rendezvous point at 18:00 UTC')">Meetup 18:00 UTC</span>
<span class="quick-chip" onclick="setQuickMessage('Private asymmetric handshake confirmed')">Asymmetric Handshake</span>
</div>
</div>
<!-- Part 2: Receiver Public Key Hand Input (Copy-Pasting by Player) -->
<div class="compose-part-card">
<div class="part-label">
<span>Part 2: Receiver Public Key</span>
<span style="font-size:10px; font-weight:600; text-transform:none; color:var(--text-muted);">Enter by hand (copy-paste)</span>
</div>
<div class="recipient-input-row">
<input
type="text"
id="recipient-pubkey-input"
class="recipient-input-field"
placeholder="Paste receiver's public key (hex 02... or 03...)"
autocomplete="off"
spellcheck="false"
>
<button class="photo2-pill-btn small" onclick="pasteRecipientKey()" title="Paste from clipboard">
📋 Paste
</button>
</div>
<div id="recipient-key-status" class="recipient-key-status">
Copy the public key from the receiver's card (click 📋) and paste it here
</div>
</div>
</div>
<!-- Lock Button for Encrypting the Message (Photo 2 Pill Style) -->
<div class="compose-actions">
<button id="lock-encrypt-btn" class="photo2-pill-btn primary" onclick="handleEncryptClick()">
<span>Encrypt Message</span>
</button>
</div>
</div>
<!-- Box 2: Encrypted Payload Box (Appears after clicking Lock button, Photo 2 Style) -->
<div id="encrypted-standalone-box" class="encrypted-standalone-box">
<div class="dialog-header">
<div class="dialog-title-group">
<h3>Encrypted Payload</h3>
<p>Ready for public wire transmission</p>
</div>
<span class="key-badge" style="background:#EBF0FF; color:#001CE0;">AES-256-GCM</span>
</div>
<div>
<div style="font-size:11px; font-weight:700; color:var(--text-muted); margin-bottom:6px; display:flex; justify-content:space-between; align-items:center;">
<span>CIPHERTEXT (Hex Payload):</span>
<button class="key-btn" onclick="copyText(document.getElementById('encrypted-ciphertext-display').textContent, 'Ciphertext')" title="Copy Ciphertext">📋</button>
</div>
<div id="encrypted-ciphertext-display" class="cipher-pill-display">
<!-- Ciphertext inserted dynamically -->
</div>
</div>
<div class="math-proof-banner">
<div><b>1. Ephemeral Key R = k · G:</b> <br><span id="encrypted-ephemeral-key" style="font-family:monospace; font-size:11px; word-break:break-all;"></span></div>
<div style="margin-top:6px;"><b>2. Shared Secret Point S = k · Q_receiver:</b> <br><span id="encrypted-shared-secret" style="font-family:monospace; font-size:11px; word-break:break-all;"></span></div>
<div style="margin-top:8px; font-size:11px; color:var(--text-muted); border-top:1px dashed rgba(0,28,224,0.15); padding-top:6px;">
Receiver uses their private key <b>d</b> to compute <b>S = d · R</b> to decrypt!
</div>
</div>
<!-- Send Button Requested in Prompt -->
<div style="display:flex; justify-content:space-between; align-items:center; margin-top:4px;">
<button class="photo2-pill-btn small" onclick="closeComposeDialog()">
Cancel
</button>
<button id="send-encrypted-msg-btn" class="photo2-pill-btn primary" onclick="handleSendClick()">
<span>Send Message</span>
</button>
</div>
</div>
</div>
</div>
<!-- Bob Character Unit (Right) -->
<section class="character-unit" id="bob-unit">
<!-- Pixel Avatar Frame (Right-clickable) -->
<div class="avatar-frame" id="bob-avatar-frame" title="Right-click Bob to send encrypted message">
<div class="avatar-halo"></div>
<!-- Exact Pixel Art from Image 1: Male hair icon (10x10) -->
<svg class="pixel-avatar-svg" viewBox="0 0 10 10" shape-rendering="crispEdges">
<!-- Row 0 -->
<rect x="3" y="0" width="4" height="1" fill="#001ce0" />
<!-- Row 1 -->
<rect x="2" y="1" width="4" height="1" fill="#001ce0" />
<rect x="7" y="1" width="1" height="1" fill="#001ce0" />
<!-- Row 2 -->
<rect x="2" y="2" width="3" height="1" fill="#001ce0" />
<rect x="6" y="2" width="2" height="1" fill="#001ce0" />
<!-- Row 3 -->
<rect x="2" y="3" width="1" height="1" fill="#001ce0" />
<rect x="7" y="3" width="1" height="1" fill="#001ce0" />
<!-- Row 4 -->
<rect x="1" y="4" width="2" height="1" fill="#001ce0" />
<rect x="7" y="4" width="2" height="1" fill="#001ce0" />
<!-- Row 5 -->
<rect x="2" y="5" width="1" height="1" fill="#001ce0" />
<rect x="7" y="5" width="1" height="1" fill="#001ce0" />
<!-- Row 6 -->
<rect x="3" y="6" width="1" height="1" fill="#001ce0" />
<rect x="6" y="6" width="1" height="1" fill="#001ce0" />
<!-- Row 7 -->
<rect x="4" y="7" width="2" height="1" fill="#001ce0" />
<!-- Row 8 -->
<rect x="2" y="8" width="2" height="1" fill="#001ce0" />
<rect x="6" y="8" width="2" height="1" fill="#001ce0" />
<!-- Row 9 -->
<rect x="0" y="9" width="10" height="1" fill="#001ce0" />
</svg>
</div>
<!-- Name in Bold Blue matching reference -->
<h2 class="character-name">BOB</h2>
<!-- Keycard Box with Photo 2 Shadowing and Style -->
<div class="character-keycard">
<!-- Public Key Field -->
<div class="key-group">
<div class="key-label-row">
<span class="key-label-title">
<span>Public Key</span>
<span class="key-badge">Q = d · G</span>
</span>
<span style="font-size:10px; color:var(--text-dim);">secp256k1</span>
</div>
<div class="key-field-pill">
<span class="key-value-text" id="bob-pubkey">Loading...</span>
<div class="key-actions-group">
<button class="key-btn" onclick="copyText(document.getElementById('bob-pubkey').textContent, 'Bob Public Key')" title="Copy Public Key">
📋
</button>
</div>
</div>
</div>
<!-- Secret Private Key Field (Asterisk Masked with SVG Reveal Eye) -->
<div class="key-group">
<div class="key-label-row">
<span class="key-label-title">
<span>Secret Private Key</span>
<span class="key-badge">d ∈ [1, n-1]</span>
</span>
<span style="font-size:10px; color:var(--text-dim);">256-bit</span>
</div>
<div class="key-field-pill">
<span class="key-value-text masked" id="bob-privkey">••••••••••••••••••••••••••••••••••••••••••••••••</span>
<div class="key-actions-group">
<!-- Clean SVG Reveal Eye Button -->
<button class="key-btn" id="bob-eye-btn" title="Toggle private key visibility">
<svg class="eye-svg" viewBox="0 0 24 24">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
<circle cx="12" cy="12" r="3"></circle>
</svg>
</button>
<button class="key-btn" onclick="copyText(state.bob.privateKeyHex, 'Bob Private Key')" title="Copy Private Key">
📋
</button>
</div>
</div>
</div>
<!-- Action Buttons -->
<div class="card-bottom-actions">
<button class="photo2-pill-btn primary" onclick="openComposeDialog('BOB')">
<span>Send Encrypted Message</span>
</button>
<div class="hint-pill">Right-click <b>Bob</b> to open context menu</div>
</div>
</div>
<!-- Bob Incoming Messages Container -->
<div id="bob-incoming-container" class="incoming-container"></div>
</section>
</div>
<!-- Communication History Section -->
<section class="history-section">
<div class="history-header">
<h4>Encrypted Transmission Log</h4>
<span id="history-count" style="font-size:12px; font-weight:700; color:var(--text-muted);">0 messages</span>
</div>
<div class="history-list" id="history-list">
<div style="text-align:center; padding:20px; color:var(--text-dim); font-size:13px;">
No encrypted messages sent yet. Right-click Alice or Bob to begin.
</div>
</div>
</main>
<!-- Main View 2: Desmos-Style 2D Elliptic Curve Graph Explorer -->
<section id="view-graph" class="graph-explorer-stage" style="display: none;">
<!-- Top Bar inside Graph View -->
<div class="graph-top-bar">
<div class="graph-title-group">
<button class="photo2-pill-btn small" onclick="switchView('simulator')">
← Back to Simulator
</button>
<div>
<h2>Elliptic Curve Graph</h2>
<p>Real-space parameter exploration & Point summation stepper</p>
</div>
</div>
<!-- Viewport zoom/pan controls -->
<div class="graph-viewport-controls">
<button class="photo2-pill-btn small" onclick="window.graphEngine?.zoomIn()" title="Zoom In">+</button>
<button class="photo2-pill-btn small" onclick="window.graphEngine?.zoomOut()" title="Zoom Out">-</button>
<button class="photo2-pill-btn small" onclick="window.graphEngine?.resetView()" title="Reset View">Reset View</button>
</div>
</div>
<!-- Main Graph Workspace Layout: Canvas on left, Controls on right -->
<div class="graph-workspace-grid">
<!-- Canvas Box with Floating Coordinates HUD -->
<div class="graph-canvas-wrapper photo2-card">
<canvas id="desmos-canvas"></canvas>
<div id="graph-cursor-hud" class="graph-cursor-hud">
Drag canvas to Pan • Scroll wheel to Zoom
</div>
</div>
<!-- Control & Explanation Sidebar -->
<div class="graph-sidebar-column">
<!-- Card 1: Changeable Variables (a & b) & Modulo Domain Toggle -->
<div class="photo2-card graph-sidebar-card">
<div class="sidebar-card-header">
<h3>Curve Parameters</h3>
<span class="formula-badge" id="graph-formula-text">y² = x³ + 7</span>
</div>
<!-- Domain Switcher: Continuous Real Curve (ℝ) vs Finite Field (mod p) -->
<div class="graph-domain-tabs">
<button id="tab-domain-real" class="domain-tab-btn active" onclick="setGraphDomain('real')">
Continuous ℝ
</button>
<button id="tab-domain-mod" class="domain-tab-btn" onclick="setGraphDomain('mod')">
Finite Field (mod p)
</button>
</div>
<div class="slider-group">
<div class="slider-label-row">
<label for="param-a-slider">Parameter a:</label>
<span id="param-a-value" class="slider-num">0.0</span>
</div>
<input type="range" id="param-a-slider" min="-5" max="5" step="0.1" value="0" class="graph-range-slider" oninput="updateParamA(this.value)">
</div>
<div class="slider-group">
<div class="slider-label-row">
<label for="param-b-slider">Parameter b:</label>
<span id="param-b-value" class="slider-num">7.0</span>
</div>
<input type="range" id="param-b-slider" min="-10" max="15" step="0.1" value="7" class="graph-range-slider" oninput="updateParamB(this.value)">
</div>
<!-- Base point xG adjustment (Real mode) -->
<div class="slider-group" id="group-param-xg">
<div class="slider-label-row">
<label for="param-xg-slider">Base Point G (X-coordinate):</label>
<span id="param-xg-value" class="slider-num">-1.5</span>
</div>
<input type="range" id="param-xg-slider" min="-2.5" max="4" step="0.1" value="-1.5" class="graph-range-slider" oninput="updateBasePointX(this.value)">
</div>
<!-- Modulo prime p selector (Mod mode) -->
<div class="slider-group" id="group-param-mod" style="display: none;">
<div class="slider-label-row">
<label>Modulus Prime (p):</label>
<span id="param-mod-value" class="slider-num">p = 23</span>
</div>
<div class="presets-row" style="margin-top: 4px;">
<button class="photo2-pill-btn small" id="prime-btn-17" onclick="setPrimeMod(17)">p = 17</button>
<button class="photo2-pill-btn small primary" id="prime-btn-23" onclick="setPrimeMod(23)">p = 23</button>
<button class="photo2-pill-btn small" id="prime-btn-43" onclick="setPrimeMod(43)">p = 43</button>
<button class="photo2-pill-btn small" id="prime-btn-67" onclick="setPrimeMod(67)">p = 67</button>
</div>
</div>
<!-- Shortcut Presets -->
<div class="presets-row">
<button class="photo2-pill-btn small primary" onclick="setPresetBitcoin()">
Bitcoin Curve (a=0, b=7)
</button>
<button class="photo2-pill-btn small" onclick="setPresetTwoComponents()">
Two-Component (a=-3, b=1)
</button>
</div>
<div id="graph-discriminant-tag" class="discriminant-tag">
Non-singular curve (Δ ≠ 0)
</div>
</div>
<!-- Card 2: Point Summation Stepper (G + G + G + ...) -->
<div class="photo2-card graph-sidebar-card">
<div class="sidebar-card-header">
<h3>Public Key Generation Stepper</h3>
<span class="stepper-count-badge" id="stepper-badge">Step d = 1</span>
</div>
<div class="stepper-info-box">
<div class="stepper-info-row">
<span class="info-label">Private Key (Scalar):</span>
<span id="stepper-private-key" class="info-val">d = 1</span>
</div>
<div class="stepper-info-row">
<span class="info-label">Public Key Point (Q = d·G):</span>
<span id="stepper-public-point" class="info-val">(-1.50, 1.90)</span>
</div>
</div>
<!-- Direct Scalar Jump Slider -->
<div class="slider-group" style="margin-top: 10px;">
<div class="slider-label-row">
<label for="stepper-step-slider">Direct Scalar Step (d):</label>
<span id="stepper-step-slider-val" class="slider-num">d = 1</span>
</div>
<input type="range" id="stepper-step-slider" min="1" max="100" step="1" value="1" class="graph-range-slider" oninput="setStepperStep(this.value)">
</div>
<!-- Stepper Buttons Row -->
<div class="stepper-buttons-row" style="margin-top: 8px;">
<button id="step-prev-btn" class="photo2-pill-btn small" onclick="stepPrevious()">
← Prev
</button>
<button id="step-next-btn" class="photo2-pill-btn small primary" onclick="stepNext()">
Next Step (+G)
</button>
<button id="step-play-btn" class="photo2-pill-btn small" onclick="togglePlaySteps()">
Auto Play
</button>
<button class="photo2-pill-btn small" onclick="resetSteps()">
Reset (1·G)
</button>
</div>
</div>
<!-- Card 3: Geometric Explanation of Current Step -->
<div class="photo2-card graph-sidebar-card">
<div class="sidebar-card-header">
<h3>Geometric Step Construction</h3>
</div>
<div id="step-math-breakdown" class="step-math-breakdown">
<div class="step-math-box">
Base Generator Point G = (-1.00, 2.45)<br>
Public Point Q = 1 · G = (-1.00, 2.45)
</div>
<div class="step-crypto-hint">
Click <b>Next Step (+G)</b> to double point G (G + G = 2G) via tangent line!
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Main View 3: Point to Address Game & Cryptographic Generators Stage -->
<section class="address-stage" id="view-point-address" style="display:none;">
<!-- Top Header & Game Status Banner -->
<div class="address-stage-header">
<div class="address-header-left">
<div class="pill-badge">
<span class="dot"></span>
<span>Bitcoin P2PKH Pipeline</span>
</div>
<h2 class="address-title">Point to Bitcoin Address</h2>
<p class="address-subtitle">
Interactive educational game: convert an elliptic curve point <code>(X, Y)</code> into a Base58 Bitcoin Address.
</p>
</div>
<div class="address-header-actions">
<button class="photo2-pill-btn small" id="p2a-btn-reset" onclick="resetAddressGame()">
<span>Reset Game</span>
</button>
<button class="photo2-pill-btn primary small" id="p2a-btn-solve-all" onclick="solveAllAddressSteps()">
<span>Solve All Steps</span>
</button>
</div>
</div>
<!-- Section 1: Predefined Point Selector & Real Hex Coordinates -->
<div class="photo2-card address-card" id="p2a-coords-card">
<div class="address-card-header">
<div class="address-step-tag">Source Point</div>
<div>
<h3 class="address-card-title">Elliptic Curve Point Coordinates (X, Y)</h3>
<p class="address-card-desc">
Public keys on secp256k1 are points <code>Q = (x, y)</code> lying on <code>y² ≡ x³ + 7 (mod p)</code>.
</p>
</div>
</div>
<!-- Point Selector Presets -->
<div class="p2a-preset-selector-row">
<span class="p2a-selector-label">Preset Point:</span>
<div class="p2a-preset-pills" id="p2a-preset-group">
<button class="p2a-preset-btn active" id="btn-preset-wiki" onclick="selectPointPreset('wiki_standard')">
Standard Vector
</button>
<button class="p2a-preset-btn" id="btn-preset-satoshi" onclick="selectPointPreset('satoshi_genesis')">
Satoshi Genesis
</button>
<button class="p2a-preset-btn" id="btn-preset-g" onclick="selectPointPreset('generator_g')">
Generator G
</button>
<button class="p2a-preset-btn" id="btn-preset-alice" onclick="selectPointPreset('alice')">
Alice's Point
</button>
<button class="p2a-preset-btn" id="btn-preset-bob" onclick="selectPointPreset('bob')">
Bob's Point
</button>
<button class="p2a-preset-btn" id="btn-preset-custom" onclick="selectPointPreset('custom')">
Custom (X, Y)
</button>
</div>
</div>
<!-- Hex Coordinates Grid -->
<div class="p2a-coords-grid">
<div class="p2a-coord-box">
<div class="p2a-coord-header">
<span class="p2a-coord-name">X Coordinate (32 bytes / 64 hex)</span>
<button class="p2a-copy-icon-btn" onclick="copyTextById('p2a-x-val')" title="Copy X Coordinate">
📋
</button>
</div>
<div class="p2a-hex-display" id="p2a-x-val">
50863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B2352
</div>
</div>
<div class="p2a-coord-box">
<div class="p2a-coord-header">
<span class="p2a-coord-name">Y Coordinate (32 bytes / 64 hex)</span>
<button class="p2a-copy-icon-btn" onclick="copyTextById('p2a-y-val')" title="Copy Y Coordinate">
📋
</button>
</div>
<div class="p2a-hex-display" id="p2a-y-val">
2CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6
</div>
</div>
</div>
<!-- Custom Input Drawer (Hidden by default) -->
<div class="p2a-custom-drawer" id="p2a-custom-drawer" style="display:none;">
<div class="p2a-custom-inputs-row">
<div class="p2a-custom-field">
<label for="p2a-input-custom-x">Custom X (Hex, 64 chars):</label>
<input type="text" id="p2a-input-custom-x" class="p2a-input" placeholder="e.g. 50863ad64a87ae...">
</div>
<div class="p2a-custom-field">
<label for="p2a-input-custom-y">Custom Y (Hex, 64 chars):</label>
<input type="text" id="p2a-input-custom-y" class="p2a-input" placeholder="e.g. 2cd470243453a2...">
</div>
<button class="photo2-pill-btn primary small" onclick="applyCustomCoordinates()" style="align-self:flex-end;">
Load Coordinates
</button>
</div>
</div>
<!-- Parity Mathematical Callout -->
<div class="p2a-parity-callout" id="p2a-parity-box">
<div class="p2a-parity-indicator">
<span class="p2a-parity-badge even" id="p2a-parity-badge">Y is EVEN</span>
<span class="p2a-parity-details" id="p2a-parity-details">
Last hex digit of Y is <b>'6'</b> (even). Compressed prefix = <code>02</code>.
</span>
</div>
<div class="p2a-parity-math-explanation">
<b>Why does this work?</b> For any point on <code>y² ≡ x³ + 7 (mod p)</code>, solving for <code>y</code> yields two symmetric square roots: <code>+y</code> and <code>-y ≡ p - y</code>. Because the prime <code>p</code> is odd, one root is always <b>even</b> and the other is always <b>odd</b>. By saving <code>02</code> (even) or <code>03</code> (odd) plus the 32-byte <code>x</code> coordinate, the full point is uniquely defined while saving 32 bytes!
</div>
</div>
</div>
<!-- Section 2: Interactive Game Stepper (6 Steps) -->
<div class="p2a-game-wrapper">
<!-- Step Navigation Pills -->
<div class="p2a-step-nav" id="p2a-step-nav">
<button class="p2a-nav-pill active" id="p2a-nav-step-1" onclick="jumpToAddressStep(1)">
<span class="p2a-nav-num">1</span>
<span class="p2a-nav-title">Format & PubKey</span>
</button>
<button class="p2a-nav-pill" id="p2a-nav-step-2" onclick="jumpToAddressStep(2)">
<span class="p2a-nav-num">2</span>
<span class="p2a-nav-title">SHA-256</span>
</button>
<button class="p2a-nav-pill" id="p2a-nav-step-3" onclick="jumpToAddressStep(3)">
<span class="p2a-nav-num">3</span>
<span class="p2a-nav-title">RIPEMD-160</span>
</button>
<button class="p2a-nav-pill" id="p2a-nav-step-4" onclick="jumpToAddressStep(4)">
<span class="p2a-nav-num">4</span>
<span class="p2a-nav-title">Network Byte</span>
</button>
<button class="p2a-nav-pill" id="p2a-nav-step-5" onclick="jumpToAddressStep(5)">
<span class="p2a-nav-num">5</span>
<span class="p2a-nav-title">Checksum</span>
</button>
<button class="p2a-nav-pill" id="p2a-nav-step-6" onclick="jumpToAddressStep(6)">
<span class="p2a-nav-num">6</span>
<span class="p2a-nav-title">Base58 Address</span>
</button>
</div>
<!-- STEP 1 CARD -->
<div class="photo2-card p2a-step-card active" id="p2a-card-step-1">
<div class="p2a-card-header-row">
<div class="p2a-step-badge">Step 1 of 6</div>
<h3 class="p2a-step-heading">Format Selection & Public Key Assembly</h3>
</div>
<p class="p2a-step-explanation">
How do we represent the 2D point <code>(X, Y)</code> as a public key string? Choose between <b>Compressed</b> and <b>Uncompressed</b> format.
</p>
<!-- Format Options -->
<div class="p2a-format-selection-group">
<div class="p2a-format-card" id="format-card-comp" onclick="setKeyFormat('compressed')">
<div class="p2a-format-radio-row">
<input type="radio" name="p2a-format" id="radio-comp" value="compressed" checked>
<label for="radio-comp"><b>Compressed Format (33 bytes / 66 hex)</b></label>
</div>
<p class="p2a-format-note">
Modern standard (BIP-137). Adds <code>02</code> if Y is even, or <code>03</code> if Y is odd, followed by X. Saves blockchain space!
</p>
</div>
<div class="p2a-format-card" id="format-card-uncomp" onclick="setKeyFormat('uncompressed')">
<div class="p2a-format-radio-row">
<input type="radio" name="p2a-format" id="radio-uncomp" value="uncompressed">
<label for="radio-uncomp"><b>Uncompressed Format (65 bytes / 130 hex)</b></label>
</div>
<p class="p2a-format-note">
Legacy Bitcoin format (2009–2012). Adds prefix <code>04</code> followed sequentially by full X and Y coordinates.
</p>
</div>
</div>
<!-- Parity Challenge (for compressed format) -->
<div class="p2a-challenge-box" id="p2a-parity-challenge-box">
<div class="p2a-challenge-question">
<b>Interactive Check:</b> Y coordinate ends in <code id="p2a-challenge-y-char">6</code>. Which prefix byte should we use?
</div>
<div class="p2a-challenge-options">
<button class="p2a-challenge-btn" id="btn-prefix-02" onclick="handlePrefixGuess('02')">
Prefix 02 (Even Y)
</button>
<button class="p2a-challenge-btn" id="btn-prefix-03" onclick="handlePrefixGuess('03')">
Prefix 03 (Odd Y)
</button>
</div>
<div class="p2a-challenge-feedback" id="p2a-prefix-feedback" style="display:none;"></div>
</div>
<!-- Assembled Public Key Output -->
<div class="p2a-output-section">
<div class="p2a-output-header">
<span class="p2a-output-label">Assembled Public Key:</span>
<span class="p2a-badge-bytes" id="p2a-pubkey-bytes-badge">33 Bytes (66 hex)</span>
<button class="p2a-copy-icon-btn" onclick="copyTextById('p2a-assembled-pubkey')" title="Copy Public Key">
📋
</button>
</div>
<div class="p2a-segmented-hex" id="p2a-assembled-pubkey">
<!-- Rendered dynamically with color chips -->
</div>
</div>
<div class="p2a-card-footer">
<button class="photo2-pill-btn primary" onclick="completeStep1AndAdvance()">
<span>Proceed to Step 2: SHA-256 ➔</span>
</button>
</div>
</div>
<!-- STEP 2 CARD: SHA-256 GENERATOR -->
<div class="photo2-card p2a-step-card" id="p2a-card-step-2">
<div class="p2a-card-header-row">
<div class="p2a-step-badge">Step 2 of 6</div>
<h3 class="p2a-step-heading">SHA-256 Hash Function</h3>
</div>
<p class="p2a-step-explanation">
Bitcoin passes the public key bytes through <b>SHA-256</b> first. This produces a fixed 256-bit (32-byte / 64 hex) digest, providing pre-image resistance and a standardized size.
</p>
<div class="p2a-generator-unit">
<div class="p2a-input-group">
<label for="p2a-step2-input">Input: Public Key Hex</label>
<input type="text" id="p2a-step2-input" class="p2a-input-mono" spellcheck="false">
</div>
<div class="p2a-generator-actions">
<button class="photo2-pill-btn primary small" onclick="runStep2Sha256()">
<span>Compute SHA-256</span>
</button>
</div>
<div class="p2a-output-group">
<div class="p2a-output-header">
<span class="p2a-output-label">SHA-256 Digest (32 bytes / 64 hex):</span>
<button class="p2a-copy-icon-btn" onclick="copyTextById('p2a-step2-output')" title="Copy SHA-256 Hash">
📋
</button>
</div>
<div class="p2a-hex-box" id="p2a-step2-output">
(Click Compute SHA-256)
</div>
</div>
</div>
<div class="p2a-card-footer">
<button class="photo2-pill-btn small" onclick="jumpToAddressStep(1)">
<span>Back</span>
</button>
<button class="photo2-pill-btn primary" id="p2a-btn-next-step2" onclick="completeStep2AndAdvance()" disabled>
<span>Proceed to Step 3: RIPEMD-160 ➔</span>
</button>
</div>
</div>
<!-- STEP 3 CARD: RIPEMD-160 GENERATOR -->
<div class="photo2-card p2a-step-card" id="p2a-card-step-3">
<div class="p2a-card-header-row">
<div class="p2a-step-badge">Step 3 of 6</div>
<h3 class="p2a-step-heading">RIPEMD-160 Hash Function (PubKeyHash)</h3>
</div>
<p class="p2a-step-explanation">
The 32-byte SHA-256 digest is fed into <b>RIPEMD-160</b> to create a compact 160-bit (20-byte / 40 hex) <b>Public Key Hash (PubKeyHash / Hash160)</b>.
<br>
<b>Why two hash algorithms?</b> If an unexpected theoretical weakness is ever found in SHA-256 or ECDSA, RIPEMD-160 still shields unspent coins!
</p>
<div class="p2a-generator-unit">
<div class="p2a-input-group">
<label for="p2a-step3-input">Input: SHA-256 Digest Hex</label>
<input type="text" id="p2a-step3-input" class="p2a-input-mono" spellcheck="false">
</div>
<div class="p2a-generator-actions">
<button class="photo2-pill-btn primary small" onclick="runStep3Ripemd160()">
<span>Compute RIPEMD-160</span>
</button>
</div>
<div class="p2a-output-group">
<div class="p2a-output-header">
<span class="p2a-output-label">PubKeyHash / Hash160 (20 bytes / 40 hex):</span>
<button class="p2a-copy-icon-btn" onclick="copyTextById('p2a-step3-output')" title="Copy PubKeyHash">
📋
</button>
</div>
<div class="p2a-hex-box" id="p2a-step3-output">
(Click Compute RIPEMD-160)
</div>
</div>
</div>
<div class="p2a-card-footer">
<button class="photo2-pill-btn small" onclick="jumpToAddressStep(2)">
<span>Back</span>
</button>
<button class="photo2-pill-btn primary" id="p2a-btn-next-step3" onclick="completeStep3AndAdvance()" disabled>
<span>Proceed to Step 4: Network Byte ➔</span>
</button>
</div>
</div>
<!-- STEP 4 CARD: NETWORK VERSION BYTE -->
<div class="photo2-card p2a-step-card" id="p2a-card-step-4">
<div class="p2a-card-header-row">
<div class="p2a-step-badge">Step 4 of 6</div>
<h3 class="p2a-step-heading">Add Bitcoin Network Version Byte (00)</h3>
</div>
<p class="p2a-step-explanation">
To specify the destination network, a 1-byte version prefix is added to the start of the 20-byte PubKeyHash.
For <b>Bitcoin Mainnet</b>, the version byte is <code>0x00</code> (Testnet uses <code>0x6F</code>).
</p>
<div class="p2a-generator-unit">
<div class="p2a-generator-actions">
<button class="photo2-pill-btn primary small" onclick="runStep4AddVersion()">
<span>Prepend Mainnet Byte (00)</span>
</button>
</div>
<div class="p2a-output-group">
<div class="p2a-output-header">
<span class="p2a-output-label">Versioned Payload (21 bytes / 42 hex):</span>
<button class="p2a-copy-icon-btn" onclick="copyTextById('p2a-step4-output-raw')" title="Copy Versioned Payload">
📋
</button>
</div>
<div class="p2a-hex-box" id="p2a-step4-output">
(Click Prepend Mainnet Byte)
</div>
<span id="p2a-step4-output-raw" style="display:none;"></span>
</div>
</div>
<div class="p2a-card-footer">
<button class="photo2-pill-btn small" onclick="jumpToAddressStep(3)">
<span>Back</span>
</button>
<button class="photo2-pill-btn primary" id="p2a-btn-next-step4" onclick="completeStep4AndAdvance()" disabled>
<span>Proceed to Step 5: Checksum ➔</span>
</button>
</div>
</div>
<!-- STEP 5 CARD: DOUBLE SHA-256 CHECKSUM -->
<div class="photo2-card p2a-step-card" id="p2a-card-step-5">
<div class="p2a-card-header-row">
<div class="p2a-step-badge">Step 5 of 6</div>
<h3 class="p2a-step-heading">Double SHA-256 Checksum Calculation</h3>
</div>
<p class="p2a-step-explanation">
To prevent catastrophic typos from burning user coins, Bitcoin performs a <b>double SHA-256 hash</b> on the 21-byte versioned payload: <code>SHA256(SHA256(payload))</code>. The first 4 bytes (8 hex chars) are appended as an error-detection checksum.
</p>
<div class="p2a-generator-unit">
<div class="p2a-generator-actions">
<button class="photo2-pill-btn primary small" onclick="runStep5Checksum()">