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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
VALIS — Variable Arrived Location In Superposition
|
| 3 |
+
Built for the Build Small Hackathon 2026.
|
| 4 |
+
|
| 5 |
+
A peer-to-peer mesh network on $10 microcontrollers.
|
| 6 |
+
Messages don't exist in transit. It's a walkie-talkie with math.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import gradio as gr
|
| 10 |
+
import os
|
| 11 |
+
import secrets
|
| 12 |
+
|
| 13 |
+
# === MEILONG SCATTER PROTOCOL ===
|
| 14 |
+
|
| 15 |
+
def xor_bytes(a, b):
|
| 16 |
+
return bytes(x ^ y for x, y in zip(a, b))
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def scatter(message):
|
| 20 |
+
"""Split a message into 3 XOR shares. Any 1 or 2 = noise. All 3 = message."""
|
| 21 |
+
data = message.encode('utf-8')
|
| 22 |
+
share1 = secrets.token_bytes(len(data))
|
| 23 |
+
share2 = secrets.token_bytes(len(data))
|
| 24 |
+
share3 = xor_bytes(xor_bytes(data, share1), share2)
|
| 25 |
+
return share1, share2, share3
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def reassemble(s1, s2, s3):
|
| 29 |
+
"""Reassemble 3 XOR shares back into the original message."""
|
| 30 |
+
return xor_bytes(xor_bytes(s1, s2), s3).decode('utf-8')
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def demo_scatter(message):
|
| 34 |
+
"""Interactive Meilong scatter demo."""
|
| 35 |
+
if not message or not message.strip():
|
| 36 |
+
return "", "", "", "", "", ""
|
| 37 |
+
|
| 38 |
+
s1, s2, s3 = scatter(message)
|
| 39 |
+
|
| 40 |
+
# Show shares as hex (proving they're noise)
|
| 41 |
+
hex1 = s1.hex()
|
| 42 |
+
hex2 = s2.hex()
|
| 43 |
+
hex3 = s3.hex()
|
| 44 |
+
|
| 45 |
+
# Try to "read" individual shares (you can't)
|
| 46 |
+
try:
|
| 47 |
+
attempt1 = s1.decode('utf-8', errors='replace')
|
| 48 |
+
except:
|
| 49 |
+
attempt1 = "[binary noise]"
|
| 50 |
+
try:
|
| 51 |
+
attempt2 = s2.decode('utf-8', errors='replace')
|
| 52 |
+
except:
|
| 53 |
+
attempt2 = "[binary noise]"
|
| 54 |
+
|
| 55 |
+
# Reassemble
|
| 56 |
+
recovered = reassemble(s1, s2, s3)
|
| 57 |
+
|
| 58 |
+
# Stats
|
| 59 |
+
stats = f"Original: {len(message)} bytes\nEach share: {len(s1)} bytes\nShares are random: share1 and share2 are crypto-random, share3 = message XOR share1 XOR share2\nIntercept 1 share: random noise\nIntercept 2 shares: random noise\nAll 3 shares: message recovers perfectly"
|
| 60 |
+
|
| 61 |
+
return hex1[:80] + "...", hex2[:80] + "...", hex3[:80] + "...", recovered, f"Decoded share 1 alone: {attempt1[:60]}...\nDecoded share 2 alone: {attempt2[:60]}...\n\nMeaningless. The message doesn't exist until all three arrive.", stats
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def demo_tamper(message, tampered_char):
|
| 65 |
+
"""Show what happens when you tamper with a share."""
|
| 66 |
+
if not message or not message.strip():
|
| 67 |
+
return "Enter a message first."
|
| 68 |
+
|
| 69 |
+
s1, s2, s3 = scatter(message)
|
| 70 |
+
|
| 71 |
+
# Tamper with share 2 — flip one byte
|
| 72 |
+
s2_tampered = bytearray(s2)
|
| 73 |
+
if len(s2_tampered) > 0:
|
| 74 |
+
pos = len(s2_tampered) // 2
|
| 75 |
+
s2_tampered[pos] = s2_tampered[pos] ^ 0xFF
|
| 76 |
+
s2_tampered = bytes(s2_tampered)
|
| 77 |
+
|
| 78 |
+
# Try to reassemble with tampered share
|
| 79 |
+
try:
|
| 80 |
+
corrupted = xor_bytes(xor_bytes(s1, s2_tampered), s3).decode('utf-8', errors='replace')
|
| 81 |
+
except:
|
| 82 |
+
corrupted = "[decode failed]"
|
| 83 |
+
|
| 84 |
+
original = reassemble(s1, s2, s3)
|
| 85 |
+
|
| 86 |
+
return f"Original message: {original}\n\nTampered reassembly: {corrupted}\n\nOne flipped byte in one share = garbage output.\nThe dragon knows when someone touched the shares."
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# === CSS ===
|
| 90 |
+
CUSTOM_CSS = """
|
| 91 |
+
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');
|
| 92 |
+
|
| 93 |
+
.gradio-container {
|
| 94 |
+
background: #0a0a12 !important;
|
| 95 |
+
max-width: 900px !important;
|
| 96 |
+
margin: 0 auto !important;
|
| 97 |
+
}
|
| 98 |
+
.gr-button-primary {
|
| 99 |
+
background: #00d4ff !important; color: #0a0a12 !important;
|
| 100 |
+
border: none !important; font-family: 'JetBrains Mono', monospace !important;
|
| 101 |
+
font-weight: bold !important;
|
| 102 |
+
}
|
| 103 |
+
.gr-button-primary:hover { background: #00b8e0 !important; }
|
| 104 |
+
footer { display: none !important; }
|
| 105 |
+
"""
|
| 106 |
+
|
| 107 |
+
SPEC_MD = """
|
| 108 |
+
## Protocol Stack
|
| 109 |
+
```
|
| 110 |
+
Layer 5: VALIS Application — Meilong scatter (3 XOR shares, 3 routes)
|
| 111 |
+
Layer 4: Identity — Presence-based (no accounts, no IP, no identity)
|
| 112 |
+
Layer 3: Mesh Routing — 802.15.4 mesh, multi-hop, self-healing
|
| 113 |
+
Layer 2: Transport — Zigbee / Thread / Wi-SUN (open standards)
|
| 114 |
+
Layer 1: Physical — 2.4GHz ISM band (license-free worldwide)
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## Hardware Per Node
|
| 118 |
+
|
| 119 |
+
| Component | Spec | Cost |
|
| 120 |
+
|-----------|------|------|
|
| 121 |
+
| ESP32-C6 or ESP32-H2 | Zigbee/Thread/802.15.4 + WiFi + BLE | $8 |
|
| 122 |
+
| USB-C cable | Powered by any outlet or battery bank | $0 |
|
| 123 |
+
| Enclosure | 3D printed or bare board | $2 |
|
| 124 |
+
| **Total** | | **$10** |
|
| 125 |
+
|
| 126 |
+
100 nodes = $1,000 (a neighborhood). 1,000 nodes = $10,000 (a town). The electrical grid already wired the topology.
|
| 127 |
+
|
| 128 |
+
## Security Model
|
| 129 |
+
|
| 130 |
+
| Attack | Result |
|
| 131 |
+
|--------|--------|
|
| 132 |
+
| **Intercept a message** | Can't. Message doesn't exist in transit. Three shares of noise on three paths. |
|
| 133 |
+
| **Identify a user** | Can't. No user identities. Nodes are anonymous. |
|
| 134 |
+
| **Shut down the network** | Can't. No server to kill. No domain to seize. Every node is independent. Kill one, traffic reroutes. |
|
| 135 |
+
| **Block the frequency** | Illegal. 2.4GHz ISM is protected by international treaty. Jamming also kills WiFi and baby monitors. |
|
| 136 |
+
| **Regulate it** | Regulate what? Open hardware, open protocols, license-free spectrum. It's a walkie-talkie with math. |
|
| 137 |
+
|
| 138 |
+
## vs. The Internet
|
| 139 |
+
|
| 140 |
+
| Feature | Internet | VALIS |
|
| 141 |
+
|---------|----------|-------|
|
| 142 |
+
| Requires ISP | Yes | No |
|
| 143 |
+
| Central servers | Yes | No |
|
| 144 |
+
| Can be censored | Yes | No |
|
| 145 |
+
| Can be surveilled | Yes | No |
|
| 146 |
+
| Requires identity | Yes | No |
|
| 147 |
+
| Can be shut down | Yes | No |
|
| 148 |
+
| Cost per node | $50-100/mo | $10 one time |
|
| 149 |
+
| Who owns it | Corporations | Nobody |
|
| 150 |
+
"""
|
| 151 |
+
|
| 152 |
+
POWERLINE_MD = """
|
| 153 |
+
## Power Line Communication — The Part Nobody Will Believe
|
| 154 |
+
|
| 155 |
+
Smart meters already send data through the electrical grid. This is not theory. It's deployed in millions of homes right now. The protocol is called G3-PLC / PRIME / IEEE 1901.2.
|
| 156 |
+
|
| 157 |
+
**The insight:** Transformers don't destroy signals — they transform them at known, predictable ratios.
|
| 158 |
+
|
| 159 |
+
### Grid Harmonics as Communication Channels
|
| 160 |
+
|
| 161 |
+
The electrical grid runs at 60Hz (US) / 50Hz (EU). But the wire carries harmonics:
|
| 162 |
+
- **120Hz** — 2nd harmonic
|
| 163 |
+
- **180Hz** — 3rd harmonic
|
| 164 |
+
- **240Hz** — 4th harmonic
|
| 165 |
+
- **300Hz** — 5th harmonic
|
| 166 |
+
|
| 167 |
+
These harmonics are *unused bandwidth*. They're considered noise by the power company. But noise is just a signal nobody's listening to.
|
| 168 |
+
|
| 169 |
+
### The Resonance Angle
|
| 170 |
+
|
| 171 |
+
Every wire has a resonant frequency determined by its length, gauge, and impedance. A VALIS node could:
|
| 172 |
+
|
| 173 |
+
1. **Listen** to the power line's harmonic signature (passive, legal, like tuning a radio)
|
| 174 |
+
2. **Inject** a tiny modulated signal on an unused harmonic (like power-line Ethernet, already legal)
|
| 175 |
+
3. **Relay** data through the grid wiring itself — no radio needed, no spectrum needed
|
| 176 |
+
|
| 177 |
+
The grid becomes the mesh. Every outlet is a node. The wiring is already there.
|
| 178 |
+
|
| 179 |
+
### 7.83Hz — The Schumann Resonance
|
| 180 |
+
|
| 181 |
+
The Earth-ionosphere cavity resonates at 7.83Hz. Tesla knew this. It's the frequency of the planet itself.
|
| 182 |
+
|
| 183 |
+
At this frequency:
|
| 184 |
+
- Signal propagates through the ground
|
| 185 |
+
- Wavelength = ~38,000 km (circumference of Earth)
|
| 186 |
+
- Extremely low power can travel extremely far
|
| 187 |
+
- Already used by submarines for communication
|
| 188 |
+
|
| 189 |
+
A VALIS node could use Schumann resonance as a *heartbeat* — a presence signal that says "I'm here" without carrying data. The data travels on the grid harmonics. The heartbeat travels through the planet.
|
| 190 |
+
|
| 191 |
+
### Why This Works
|
| 192 |
+
|
| 193 |
+
Power Line Communication is already FCC-approved, already deployed, already proven. VALIS just:
|
| 194 |
+
1. Uses open frequencies the power company considers noise
|
| 195 |
+
2. Adds Meilong scatter so the data is meaningless in transit
|
| 196 |
+
3. Adds mesh routing so there's no center to attack
|
| 197 |
+
|
| 198 |
+
The grid is the largest mesh network ever built. It just doesn't know it yet.
|
| 199 |
+
"""
|
| 200 |
+
|
| 201 |
+
# === APP ===
|
| 202 |
+
with gr.Blocks(css=CUSTOM_CSS, title="VALIS", theme=gr.themes.Base()) as app:
|
| 203 |
+
|
| 204 |
+
gr.HTML("""
|
| 205 |
+
<div style="text-align:center; padding: 24px 0 8px;">
|
| 206 |
+
<h1 style="font-family: 'JetBrains Mono', monospace; color: #00d4ff; font-size: 2.8em; letter-spacing: 0.2em;">
|
| 207 |
+
VALIS
|
| 208 |
+
</h1>
|
| 209 |
+
<p style="font-family: 'JetBrains Mono', monospace; color: #444; font-size: 0.8em; letter-spacing: 0.1em;">
|
| 210 |
+
Variable Arrived Location In Superposition
|
| 211 |
+
</p>
|
| 212 |
+
<p style="font-family: 'JetBrains Mono', monospace; color: #333; font-size: 0.65em; max-width: 500px; margin: 8px auto;">
|
| 213 |
+
Peer-to-peer mesh network. $10 nodes. Messages don't exist in transit.
|
| 214 |
+
No server. No company. No identity. It's a walkie-talkie with math.
|
| 215 |
+
</p>
|
| 216 |
+
</div>
|
| 217 |
+
""")
|
| 218 |
+
|
| 219 |
+
with gr.Tabs():
|
| 220 |
+
|
| 221 |
+
with gr.TabItem("Meilong Scatter Demo"):
|
| 222 |
+
gr.Markdown("### Type a message. Watch it shatter into noise. Watch it reassemble.")
|
| 223 |
+
msg_input = gr.Textbox(label="Your message", placeholder="The dragon sleeps between the nodes.", lines=2)
|
| 224 |
+
|
| 225 |
+
scatter_btn = gr.Button("SCATTER", variant="primary", size="lg")
|
| 226 |
+
|
| 227 |
+
with gr.Row():
|
| 228 |
+
share1 = gr.Textbox(label="Share 1 (hex)", interactive=False)
|
| 229 |
+
share2 = gr.Textbox(label="Share 2 (hex)", interactive=False)
|
| 230 |
+
share3 = gr.Textbox(label="Share 3 (hex)", interactive=False)
|
| 231 |
+
|
| 232 |
+
recovered = gr.Textbox(label="Reassembled (all 3 shares combined)", interactive=False)
|
| 233 |
+
intercept = gr.Textbox(label="What happens if you intercept 1-2 shares", lines=4, interactive=False)
|
| 234 |
+
stats = gr.Textbox(label="Stats", lines=5, interactive=False)
|
| 235 |
+
|
| 236 |
+
scatter_btn.click(
|
| 237 |
+
fn=demo_scatter,
|
| 238 |
+
inputs=[msg_input],
|
| 239 |
+
outputs=[share1, share2, share3, recovered, intercept, stats],
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
gr.Markdown("### Tamper Detection")
|
| 243 |
+
gr.Markdown("What happens when someone modifies a share in transit?")
|
| 244 |
+
tamper_msg = gr.Textbox(label="Message to tamper with", placeholder="Try to break this", lines=1)
|
| 245 |
+
tamper_btn = gr.Button("SCATTER + TAMPER", variant="primary")
|
| 246 |
+
tamper_result = gr.Textbox(label="Result", lines=5, interactive=False)
|
| 247 |
+
|
| 248 |
+
tamper_btn.click(
|
| 249 |
+
fn=demo_tamper,
|
| 250 |
+
inputs=[tamper_msg, gr.Textbox(visible=False, value="x")],
|
| 251 |
+
outputs=[tamper_result],
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
with gr.TabItem("Architecture"):
|
| 255 |
+
gr.Markdown(SPEC_MD)
|
| 256 |
+
|
| 257 |
+
with gr.TabItem("Power Line Communication"):
|
| 258 |
+
gr.Markdown(POWERLINE_MD)
|
| 259 |
+
|
| 260 |
+
with gr.TabItem("Build a Node"):
|
| 261 |
+
gr.Markdown("""
|
| 262 |
+
## Build One Right Now
|
| 263 |
+
|
| 264 |
+
**Parts:**
|
| 265 |
+
- 1x ESP32-C6 DevKit — $8 (Amazon, AliExpress, Adafruit)
|
| 266 |
+
- 1x USB-C cable — $2 or use one you have
|
| 267 |
+
|
| 268 |
+
**Total: $10**
|
| 269 |
+
|
| 270 |
+
Plug it into any outlet. It joins the mesh. That's it.
|
| 271 |
+
|
| 272 |
+
### At Scale
|
| 273 |
+
- 100 nodes = $1,000 (a neighborhood)
|
| 274 |
+
- 1,000 nodes = $10,000 (a town)
|
| 275 |
+
- 10,000 nodes = $100,000 (a city)
|
| 276 |
+
- The electrical grid already wired the topology. We just add brains.
|
| 277 |
+
|
| 278 |
+
### What It's For
|
| 279 |
+
- Messaging that can't be intercepted or censored
|
| 280 |
+
- Community networks that don't need an ISP
|
| 281 |
+
- Emergency communication when internet goes down
|
| 282 |
+
- IoT mesh that doesn't phone home to corporate servers
|
| 283 |
+
- Protests, journalism, activism in hostile environments
|
| 284 |
+
|
| 285 |
+
### What It's NOT For
|
| 286 |
+
- Streaming Netflix
|
| 287 |
+
- Social media
|
| 288 |
+
- Anything requiring high bandwidth
|
| 289 |
+
- Crime (the network is ownerless but the law still applies to people)
|
| 290 |
+
|
| 291 |
+
### The Rule
|
| 292 |
+
There is no company. There is no board. There is no token. There is no foundation.
|
| 293 |
+
There is a $10 device and a document that tells you how to build one.
|
| 294 |
+
The children of Philadelphia get the rest.
|
| 295 |
+
""")
|
| 296 |
+
|
| 297 |
+
gr.HTML("""
|
| 298 |
+
<div style="text-align:center; padding: 16px 0 4px; color: #333; font-size: 0.65em; font-family: 'JetBrains Mono', monospace; line-height: 1.8;">
|
| 299 |
+
No model needed. Pure math. Meilong scatter: 3 XOR shares, 3 routes, zero trust required.<br>
|
| 300 |
+
<span style="color:#00d4ff;">Heuremen — Build Small Hackathon 2026</span><br>
|
| 301 |
+
<span style="color:#333; font-style: italic;">"The dragon sleeps between the nodes."</span>
|
| 302 |
+
</div>
|
| 303 |
+
""")
|
| 304 |
+
|
| 305 |
+
if __name__ == "__main__":
|
| 306 |
+
app.launch()
|