-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathras_ui.html
More file actions
601 lines (550 loc) · 19.6 KB
/
Copy pathras_ui.html
File metadata and controls
601 lines (550 loc) · 19.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Real-Time Asymmetric Vision Encryption - Project Demo</title>
<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&display=swap" rel="stylesheet" />
<style>
:root {
--color-background: #111827;
--color-card-bg: #1f2937;
--color-border: #374151;
--color-text-light: #f9fafb;
--color-text-muted: #9ca3af;
--color-primary-accent: #6366f1;
--color-secondary-accent: #38bdf8;
--color-button-start: #22c55e;
--color-button-stop: #ef4444;
--color-success: #22c55e;
--color-warning: #facc15;
--color-error: #ef4444;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: var(--color-background);
color: var(--color-text-light);
min-height: 100vh;
line-height: 1.6;
padding: 32px 16px 40px;
}
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.hero {
text-align: center;
padding: 60px 0;
margin-bottom: 60px;
background: linear-gradient(180deg, var(--color-background) 0%, #0c101a 100%);
border-radius: 12px;
margin-top: 20px;
border: 1px solid var(--color-border);
}
.hero-tagline {
font-size: 0.9rem;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--color-secondary-accent);
margin-bottom: 12px;
font-weight: 600;
}
.hero h1 {
font-size: clamp(2.5rem, 5vw, 4.5rem);
font-weight: 700;
margin-bottom: 20px;
line-height: 1.1;
}
.hero h1 .highlight { color: var(--color-primary-accent); }
.hero p {
font-size: clamp(1rem, 2vw, 1.25rem);
color: var(--color-text-muted);
max-width: 700px;
margin: 0 auto 30px;
}
.hero-actions {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
flex-direction: column;
}
.hero-btn {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 14px 28px;
border-radius: 8px;
border: none;
font-size: 1.05rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease-in-out;
text-decoration: none;
color: var(--color-text-light);
}
.hero-btn.primary {
background: var(--color-primary-accent);
box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}
.hero-btn.primary:hover {
background: #4f46e5;
transform: translateY(-2px);
box-shadow: 0 12px 25px rgba(99, 102, 241, 0.5);
}
.feature-highlights {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 40px;
margin-top: 40px;
}
.feature-item {
text-align: center;
color: var(--color-text-muted);
font-size: 0.95rem;
}
.feature-item strong {
display: block;
font-size: 1.8rem;
font-weight: 700;
color: var(--color-secondary-accent);
margin-bottom: 5px;
}
.section-heading {
text-align: center;
margin-bottom: 40px;
}
.section-heading h2 {
font-size: clamp(1.8rem, 3.5vw, 2.8rem);
font-weight: 700;
margin-bottom: 10px;
}
.section-heading p {
font-size: 1.1rem;
color: var(--color-text-muted);
max-width: 600px;
margin: 0 auto;
}
.demo-card {
background: var(--color-card-bg);
border-radius: 12px;
border: 1px solid var(--color-border);
padding: 28px;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
margin-bottom: 60px;
}
.card-title { font-size: 1.5rem; font-weight: 600; margin-bottom: 8px; }
.card-subtitle { font-size: 1rem; color: var(--color-text-muted); margin-bottom: 24px; }
.status-bar {
display: flex;
flex-wrap: wrap;
gap: 15px 30px;
align-items: center;
font-size: 0.9rem;
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px dashed var(--color-border);
}
.status-item {
display: flex;
align-items: center;
gap: 8px;
color: var(--color-text-muted);
}
.dot {
width: 10px;
height: 10px;
border-radius: 999px;
background: var(--color-border);
transition: background 0.3s ease;
}
.dot.ok { background: var(--color-success); }
.dot.warn { background: var(--color-warning); }
.dot.error { background: var(--color-error); }
.action-btn {
display: block;
width: 100%;
padding: 14px 28px;
border-radius: 8px;
border: none;
background: var(--color-button-start);
color: white;
font-size: 1.15rem;
font-weight: 600;
cursor: pointer;
transition: background 0.2s ease, transform 0.1s ease,
box-shadow 0.2s ease, opacity 0.2s ease;
box-shadow: 0 6px 20px rgba(34, 197, 94, 0.3);
margin-bottom: 20px;
}
.action-btn:hover:not(:disabled) {
background: #16a34a;
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(34, 197, 94, 0.4);
}
.action-btn:disabled {
opacity: 0.6;
cursor: default;
box-shadow: none;
transform: none;
}
.action-btn.stop {
background: var(--color-button-stop);
box-shadow: 0 6px 20px rgba(239, 68, 68, 0.3);
}
.action-btn.stop:hover:not(:disabled) {
background: #dc2626;
box-shadow: 0 10px 25px rgba(239, 68, 68, 0.4);
}
.video-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 24px;
margin-top: 20px;
}
.video-panel {
background: #0f172a;
border-radius: 10px;
border: 1px solid var(--color-border);
padding: 15px;
position: relative;
}
.panel-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.panel-title-text {
font-size: 1.05rem;
font-weight: 500;
color: var(--color-secondary-accent);
}
.panel-tag {
font-size: 0.75rem;
padding: 4px 10px;
border-radius: 999px;
background: rgba(99, 102, 241, 0.1);
border: 1px solid rgba(99, 102, 241, 0.3);
color: var(--color-secondary-accent);
}
video,
img {
width: 100%;
height: 280px;
border-radius: 8px;
border: 1px solid var(--color-border);
background: #020617;
object-fit: cover;
display: block;
}
img#encryptedImg {
object-fit: contain;
background: radial-gradient(circle at center, #1f2937, #020617 70%);
}
.demo-note {
font-size: 0.85rem;
color: var(--color-text-muted);
margin-top: 30px;
padding: 15px 20px;
background: var(--color-background);
border-left: 4px solid var(--color-primary-accent);
border-radius: 8px;
line-height: 1.5;
}
.demo-note code {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 0.82rem;
background: #2d3748;
border-radius: 4px;
padding: 2px 6px;
border: 1px solid var(--color-border);
color: var(--color-text-light);
}
footer {
text-align: center;
margin-top: 60px;
font-size: 0.85rem;
color: var(--color-text-muted);
padding-top: 20px;
border-top: 1px solid var(--color-border);
}
@media (max-width: 768px) {
.hero { padding: 40px 0; margin-bottom: 40px; }
.hero-actions { flex-direction: column; gap: 15px; }
.hero-btn { width: 80%; max-width: 300px; }
.feature-highlights { gap: 25px; }
.feature-item strong { font-size: 1.5rem; }
.section-heading h2 { font-size: 2rem; }
.demo-card { padding: 20px; }
.status-bar {
flex-direction: column;
align-items: flex-start;
gap: 10px;
}
video, img { height: 200px; }
}
</style>
</head>
<body>
<div class="container">
<header class="hero">
<div class="hero-tagline">Pure RSA Demo</div>
<h1>Real-Time Asymmetric <span class="highlight">Vision Encryption</span></h1>
<p>
Proof-of-concept: each live video frame is encrypted and decrypted using only RSA,
showing original, encrypted, and decrypted views side by side.
</p>
<div class="hero-actions">
<a href="#demo-section" class="hero-btn primary">Start Live Demo</a>
<div class="feature-highlights">
<div class="feature-item">
<strong>1024-bit</strong>
RSA Modulus (demo)
</div>
<div class="feature-item">
<strong>Pure RSA</strong>
No symmetric cipher
</div>
<div class="feature-item">
<strong>Grayscale</strong>
Pixel-wise Encryption
</div>
</div>
</div>
</header>
<section id="demo-section" class="section-heading">
<h2>See It In Action</h2>
<p>
Left: original camera feed. Middle: RSA-encrypted frame (visualized noise).
Right: decrypted frame (receiver’s view after RSA decryption).
</p>
</section>
<section class="demo-card">
<div class="card-title">Live RSA Encryption Demo</div>
<div class="card-subtitle">
Allow camera access, then start the loop to see original, encrypted, and decrypted frames side by side.
</div>
<!-- RSA INFO PANEL -->
<div class="demo-card" style="margin-bottom:20px;">
<h2 style="color:#38bdf8; font-size:1.4rem; margin-bottom:10px;">RSA Cryptography Details</h2>
<div style="background:#1f2937; padding:15px; border-radius:10px; border:1px solid #374151; font-size:14px; word-wrap:break-word;">
<strong>Modulus N:</strong>
<div id="rsaN" style="margin-bottom:10px;">Loading…</div>
<strong>Public Exponent E:</strong>
<div id="rsaE" style="margin-bottom:10px;">Loading…</div>
<strong>Key Size:</strong>
<div id="rsaBits">Loading…</div>
</div>
</div>
<button id="toggleBtn" class="action-btn" disabled>Loading camera…</button>
<div class="status-bar">
<div class="status-item">
<span id="cameraDot" class="dot"></span>
<span id="cameraStatus">Camera: initializing…</span>
</div>
<div class="status-item">
<span id="encryptDot" class="dot warn"></span>
<span id="encryptStatus">Encryption: idle</span>
</div>
</div>
<div class="video-grid">
<!-- Original -->
<div class="video-panel">
<div class="panel-header">
<span class="panel-title-text">Live Camera Feed</span>
<span class="panel-tag">Original Source</span>
</div>
<video id="camera" autoplay muted playsinline></video>
</div>
<!-- Encrypted -->
<div class="video-panel">
<div class="panel-header">
<span class="panel-title-text">Encrypted Output</span>
<span class="panel-tag">RSA Cipher (visualized)</span>
</div>
<img id="encryptedImg" src="" alt="Encrypted frame will appear here" />
<div style="font-size:0.9rem; margin-top:10px; color:#9ca3af;">
Ciphertext values are reduced mod 256 so they can be displayed as an image.
</div>
</div>
<!-- Decrypted -->
<div class="video-panel">
<div class="panel-header">
<span class="panel-title-text">Decrypted Output</span>
<span class="panel-tag">Receiver View (RSA)</span>
</div>
<img id="decryptedImg" src="" alt="Decrypted frame will appear here" />
</div>
</div>
<p class="demo-note">
Backend endpoints:<br />
• <code>GET /rsa-info</code> → RSA modulus, exponent, key size<br />
• <code>POST /encrypt</code> → JSON <code>{"image": "data:image/png;base64,..."}</code><br />
Returns RSA-encrypted and RSA-decrypted frames plus timing and verification stats.
</p>
</section>
<footer>
<p>Project Demo © 2025 | Real-Time Asymmetric Vision Encryption (Pure RSA, 1024-bit)</p>
</footer>
</div>
<canvas id="canvas" width="320" height="240" style="display:none;"></canvas>
<div id="cryptoRuntime" style="margin-top:10px; font-size:0.85rem; color:#9ca3af; max-width:1200px; margin-left:auto; margin-right:auto;">
<p>
<strong style="color:#38bdf8;">Crypto Status:</strong>
<span style="color:#9ca3af;">(RSA encryption + RSA decryption on each frame)</span>
</p>
<p id="frameCount">Frames Encrypted with RSA: 0</p>
<p id="rsaTime">RSA Encrypt Time per Frame: calculating…</p>
<p id="rsaDecryptTime">RSA Decrypt Time per Frame: calculating…</p>
<p id="decryptOk">Decryption Check: waiting…</p>
<p id="pixelCount">Pixels Processed by RSA: calculating…</p>
</div>
<script>
const video = document.getElementById("camera");
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const encryptedImg = document.getElementById("encryptedImg");
const decryptedImg = document.getElementById("decryptedImg");
const btn = document.getElementById("toggleBtn");
const cameraStatus = document.getElementById("cameraStatus");
const cameraDot = document.getElementById("cameraDot");
const encryptStatus = document.getElementById("encryptStatus");
const encryptDot = document.getElementById("encryptDot");
let encrypting = false;
let intervalId = null;
let stream = null;
async function loadRSAInfo() {
try {
const res = await fetch("/rsa-info");
const info = await res.json();
document.getElementById("rsaN").textContent = info.N;
document.getElementById("rsaE").textContent = info.E;
document.getElementById("rsaBits").textContent = info.bits + " bits";
} catch (err) {
console.error("RSA info load error:", err);
document.getElementById("rsaN").textContent = "Error loading RSA info";
document.getElementById("rsaE").textContent = "-";
document.getElementById("rsaBits").textContent = "-";
}
}
loadRSAInfo();
async function startCamera() {
try {
cameraStatus.textContent = "Camera: requesting permission…";
stream = await navigator.mediaDevices.getUserMedia({ video: true });
video.srcObject = stream;
cameraStatus.textContent = "Camera: ready";
cameraDot.className = "dot ok";
btn.disabled = false;
btn.textContent = "Start RSA Encryption";
} catch (err) {
console.error("getUserMedia error:", err);
cameraStatus.textContent = "Camera: unavailable (in use or blocked)";
cameraDot.className = "dot error";
btn.disabled = true;
}
}
startCamera();
function stopCamera() {
if (stream) {
stream.getTracks().forEach(t => t.stop());
stream = null;
video.srcObject = null;
cameraStatus.textContent = "Camera: stopped";
cameraDot.className = "dot warn";
}
}
function startEncryption() {
if (encrypting) return;
if (!stream) {
console.warn("Camera stream not ready");
return;
}
encrypting = true;
btn.textContent = "Stop RSA Encryption";
btn.classList.add("stop");
encryptStatus.textContent = "Encryption: running…";
encryptDot.className = "dot ok";
intervalId = setInterval(captureAndEncrypt, 400); // ~2.5 FPS for 1024-bit RSA
}
function stopEncryption() {
if (!encrypting) return;
encrypting = false;
if (intervalId !== null) {
clearInterval(intervalId);
intervalId = null;
}
btn.textContent = "Start RSA Encryption";
btn.classList.remove("stop");
encryptStatus.textContent = "Encryption: idle";
encryptDot.className = "dot warn";
encryptedImg.src = "";
decryptedImg.src = "";
document.getElementById("rsaDecryptTime").textContent = "RSA Decrypt Time per Frame: calculating…";
document.getElementById("rsaTime").textContent = "RSA Encrypt Time per Frame: calculating…";
document.getElementById("decryptOk").textContent = "Decryption Check: waiting…";
document.getElementById("frameCount").textContent = "Frames Encrypted with RSA: 0";
document.getElementById("pixelCount").textContent = "Pixels Processed by RSA: calculating…";
}
btn.addEventListener("click", () => {
if (!encrypting) startEncryption();
else stopEncryption();
});
async function captureAndEncrypt() {
if (!encrypting) return;
if (!video.srcObject) return;
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
const dataUrl = canvas.toDataURL("image/png");
try {
const response = await fetch("/encrypt", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ image: dataUrl })
});
const result = await response.json();
if (result.error) throw new Error(result.error);
if (!encrypting) return;
if (result.encrypted_image) {
encryptedImg.src = result.encrypted_image;
}
if (result.decrypted_image) {
decryptedImg.src = result.decrypted_image;
}
if (typeof result.frame_count !== "undefined") {
document.getElementById("frameCount").textContent =
"Frames Encrypted with RSA: " + result.frame_count;
}
if (typeof result.rsa_time_ms !== "undefined") {
document.getElementById("rsaTime").textContent =
"RSA Encrypt Time per Frame: " + result.rsa_time_ms + " ms";
}
if (typeof result.rsa_decrypt_time_ms !== "undefined") {
document.getElementById("rsaDecryptTime").textContent =
"RSA Decrypt Time per Frame: " + result.rsa_decrypt_time_ms + " ms";
}
if (typeof result.decryption_ok !== "undefined") {
const ok = result.decryption_ok;
const el = document.getElementById("decryptOk");
el.textContent = "Decryption Check: " + (ok ? "OK" : "FAILED");
el.style.color = ok ? "#22c55e" : "#ef4444";
}
if (typeof result.pixel_count !== "undefined") {
document.getElementById("pixelCount").textContent =
"Pixels Processed by RSA: " + result.pixel_count;
}
} catch (err) {
console.error("Encryption error:", err);
stopEncryption();
encryptStatus.textContent = "Encryption: error";
encryptDot.className = "dot error";
}
}
window.addEventListener("beforeunload", () => {
stopEncryption();
stopCamera();
});
</script>
</body>
</html>