Skip to content

Commit 8034ed7

Browse files
Added demo
1 parent 63d4c96 commit 8034ed7

File tree

5 files changed

+519
-0
lines changed

5 files changed

+519
-0
lines changed

demo_input.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+

2+
y
3+
y
4+
5+
6+
5.0
7+
0.5
8+
q
9+
10+
y

demo_output.txt

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+

2+
============================================================
3+
QUANTUM-SAFE FEDERATED LEARNING DEMO
4+
============================================================
5+
6+
Welcome to the Interactive Cybersecurity Demo!
7+
This walkthrough demonstrates the security layers protecting your ML system.
8+
9+
Press Enter to begin...
10+
============================================================
11+
CHAPTER 1: The Quantum-Safe Handshake
12+
============================================================
13+
14+
Initializing Post-Quantum Cryptography modules...
15+
[OK] Server generating Kyber-768 keypair...
16+
Public Key (truncated): 09e2c13cb533c4bb300144a9dba0a6ad...
17+
[OK] Client encapsulating shared secret...
18+
Ciphertext (truncated): 722533c24847b1daf447dce7a5711803...
19+
[OK] Server decapsulating to recover session key...
20+
[OK] Session keys match! (256-bit AES key established)
21+
22+
[INFO] Generating Dilithium identity for client...
23+
[OK] Update signed! Signature: f8a539eae7f98bd5d3a237dd15ff14cf...
24+
25+
Would you like to attempt a Man-in-the-Middle attack? (y/n):
26+
[INTERCEPT] Capturing network traffic...
27+
28+
.
29+
..
30+
...
31+
[WARN] Packet captured! Attempting to decode...
32+
33+
--- ENCRYPTED PAYLOAD (Server View) ---
34+
F53F 66D0 7C62 CEDE 12F6 0EA1 CFDD C56B 6D1C 4E4E E80F D11D 905C 1DB6 E8B2 7337
35+
FB47 598D FE3A C167 9A03 0553 253B D629 23F2 E5C5 BBEA 6D57 CD38 71E7 2C04 38E2
36+
9140 954A 27A8 7AC8 4360 FF6C E6B6 9B9A 7B80 9A24 7279 8C27 5729 A904 5006 A2A6
37+
--- END ENCRYPTED ---
38+
39+
Try to modify the intercepted weights? (y/n): [WARN] Weights modified to [9.9, 9.9, 9.9]!
40+
[CRITICAL] DILITHIUM SIGNATURE MISMATCH! Update REJECTED.
41+
42+
Press Enter to continue to Chapter 2...
43+
============================================================
44+
CHAPTER 2: The Server's Blindfold (Homomorphic Encryption)
45+
============================================================
46+
47+
Initializing Paillier Homomorphic Encryption (2048-bit)...
48+
[OK] Paillier HE initialized (key_size=2048 bits)
49+
[OK] HE Keypair generated.
50+
51+
Client's Plaintext Weights:
52+
[ 0.25 -0.15 0.88]
53+
[INFO] Client encrypting weights with HE...
54+
55+
Server's View (Encrypted):
56+
16605985097313860610552461006730510262867751819821907223542044271408170231908535...
57+
58+
--- ENCRYPTED PAYLOAD (Server View) ---
59+
597D 0877 33B4 4E19 8C58 3595 44DE 143C 816C 834B 2B9C FA60 0026 25CE 98F9 E7CE
60+
ED62 EE03 03A0 239C CDA6 8C48 5DB2 6DE3 B7A1 471A DE29 BEC4 D9B3 1A1E 618D 4A4A
61+
--- END ENCRYPTED ---
62+
63+
[INFO] Simulating second client's encrypted weights...
64+
[INFO] Server adding encrypted vectors (BLINDFOLDED)...
65+
[OK] Encrypted sum computed. Server still sees nothing!
66+
[INFO] Decrypting final aggregate...
67+
68+
Decrypted Result: [0.35 0.05 1. ]
69+
Expected (Plaintext Sum): [0.35 0.05 1. ]
70+
[OK] Results match! Privacy-preserving aggregation successful.
71+
72+
Press Enter to continue to Chapter 3...
73+
============================================================
74+
CHAPTER 3: The Privacy Blur (Differential Privacy)
75+
============================================================
76+
77+
Differential Privacy adds calibrated noise to protect individual data.
78+
Lower epsilon = More noise = More privacy (but less accuracy).
79+
80+
Enter epsilon value (0.1 - 10.0), or 'q' to quit:
81+
Privacy Blur Visualization (epsilon = 5.0)
82+
#
83+
###
84+
#####
85+
#######
86+
#########
87+
=> LOW NOISE (Less Private)
88+
89+
Simulated Accuracy: 81.60% (Baseline: 84%)
90+
91+
Enter epsilon value (0.1 - 10.0), or 'q' to quit:
92+
Privacy Blur Visualization (epsilon = 0.5)
93+
# # # # # # # #
94+
# # # # # # # #
95+
#################
96+
#################
97+
#################
98+
=> HIGH NOISE (Very Private)
99+
100+
Simulated Accuracy: 60.00% (Baseline: 84%)
101+
102+
Enter epsilon value (0.1 - 10.0), or 'q' to quit:
103+
Press Enter to continue to Chapter 4...
104+
============================================================
105+
CHAPTER 4: Quantum Attack Defense
106+
============================================================
107+
108+
This system uses NIST-standardized Post-Quantum Cryptography.
109+
Even if a quantum computer tries to break the encryption, we're ready.
110+
111+
Simulate a Quantum Attack? (y/n):
112+
[ALERT] Quantum Attack Detected!
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+
[INFO] Pattern matching Shor's Algorithm signatures...
140+
[WARN] Initiating Kyber-768 key rotation...
141+
[OK] Channel re-secured. Quantum breach averted.
142+
143+
144+
[OK] All chapters complete!
145+
146+
============================================================
147+
DEMO COMPLETE
148+
============================================================
149+
150+
Your Quantum-Safe Federated Learning System is ready for evaluation.
151+

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ phe>=1.5.0
1313

1414
# Visualization
1515
matplotlib>=3.7.0
16+
colorama>=0.4.6
1617

1718
# Optional
1819
scipy>=1.11.0

src/demo_visuals.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
Demo Visuals: ASCII Art, Animations, and Colorized Output
3+
for the Interactive Cybersecurity Demo.
4+
"""
5+
6+
import time
7+
import random
8+
from colorama import Fore, Style, init
9+
10+
# Initialize colorama for Windows compatibility
11+
init(autoreset=True)
12+
13+
# --- Color Shortcuts ---
14+
OK = Fore.GREEN
15+
WARN = Fore.YELLOW
16+
CRIT = Fore.RED
17+
INFO = Fore.CYAN
18+
BOLD = Style.BRIGHT
19+
RESET = Style.RESET_ALL
20+
21+
22+
def print_banner(title: str):
23+
"""Print a styled header banner."""
24+
width = 60
25+
print()
26+
print(f"{BOLD}{INFO}{'='*width}")
27+
print(f"{title.center(width)}")
28+
print(f"{'='*width}{RESET}")
29+
print()
30+
31+
32+
def print_status(level: str, msg: str):
33+
"""Print a status message with colored level indicator."""
34+
colors = {
35+
"ok": OK,
36+
"warn": WARN,
37+
"critical": CRIT,
38+
"info": INFO,
39+
}
40+
color = colors.get(level.lower(), RESET)
41+
print(f" {color}[{level.upper()}]{RESET} {msg}")
42+
43+
44+
def print_ciphertext_wall(data: str, lines: int = 5, delay: float = 0.03):
45+
"""Print a 'Matrix-style' wall of hex ciphertext."""
46+
hex_chars = "0123456789ABCDEF"
47+
width = 64
48+
49+
print(f"\n{BOLD}{Fore.GREEN}--- ENCRYPTED PAYLOAD (Server View) ---{RESET}")
50+
for _ in range(lines):
51+
line = "".join(random.choice(hex_chars) for _ in range(width))
52+
# Insert spaces for readability
53+
formatted = " ".join(line[i:i+4] for i in range(0, len(line), 4))
54+
print(f" {Fore.GREEN}{formatted}{RESET}")
55+
time.sleep(delay)
56+
print(f"{BOLD}{Fore.GREEN}--- END ENCRYPTED ---{RESET}\n")
57+
58+
59+
def print_dp_blur(epsilon: float):
60+
"""Print an ASCII histogram showing noise distribution at given epsilon."""
61+
# Higher epsilon = less noise = sharper distribution
62+
# Lower epsilon = more noise = wider distribution
63+
print(f"\n{INFO}Privacy Blur Visualization (epsilon = {epsilon}){RESET}")
64+
65+
# Simulate a simple ASCII Gaussian-like distribution
66+
if epsilon >= 5.0:
67+
bars = [" # ", " ### ", " ##### ", " ####### ", " ######### "]
68+
label = "LOW NOISE (Less Private)"
69+
elif epsilon >= 1.0:
70+
bars = [" # # ", " ### ### ", "##### #####", "####### #######", "###############"]
71+
label = "MEDIUM NOISE (Balanced)"
72+
else:
73+
bars = ["# # # # # # # #", "# # # # # # # #", "#################", "#################", "#################"]
74+
label = "HIGH NOISE (Very Private)"
75+
76+
for bar in bars:
77+
print(f" {Fore.MAGENTA}{bar}{RESET}")
78+
print(f" {WARN}=> {label}{RESET}\n")
79+
80+
81+
def animate_quantum_attack(duration: float = 2.0):
82+
"""Display an animated Quantum Attack wave."""
83+
print(f"\n{CRIT}{BOLD}[ALERT] Quantum Attack Detected!{RESET}")
84+
85+
wave_chars = "_.-~^~-._"
86+
width = 40
87+
frames = int(duration / 0.1)
88+
89+
for i in range(frames):
90+
offset = i % len(wave_chars)
91+
wave = "".join(wave_chars[(j + offset) % len(wave_chars)] for j in range(width))
92+
print(f"\r {Fore.CYAN}{wave}{RESET}", end="", flush=True)
93+
time.sleep(0.1)
94+
95+
print() # Newline after animation
96+
print_status("info", "Pattern matching Shor's Algorithm signatures...")
97+
time.sleep(0.5)
98+
print_status("warn", "Initiating Kyber-768 key rotation...")
99+
time.sleep(0.5)
100+
print_status("ok", "Channel re-secured. Quantum breach averted.")
101+
print()
102+
103+
104+
def animate_mitm_intercept():
105+
"""Display a Man-in-the-Middle interception animation."""
106+
print(f"\n{WARN}[INTERCEPT] Capturing network traffic...{RESET}")
107+
108+
for i in range(3):
109+
print(f"\r {'.' * (i+1)}", end="", flush=True)
110+
time.sleep(0.3)
111+
print()
112+
113+
print_status("warn", "Packet captured! Attempting to decode...")
114+
time.sleep(0.5)
115+
116+
117+
def print_comparison(client_view: str, server_view: str):
118+
"""Print a side-by-side comparison of client vs server view."""
119+
print(f"\n{BOLD}Client View (Plaintext):{RESET}")
120+
print(f" {OK}{client_view}{RESET}")
121+
print(f"\n{BOLD}Server View (Ciphertext):{RESET}")
122+
print(f" {Fore.GREEN}{server_view[:60]}...{RESET}")
123+
print()

0 commit comments

Comments
 (0)