1. Hub-and-Spoke Architecture
A central WebSocket relay (Bun server) simply bounces your traffic across the wire. It does not store passwords, keys, or messages. When you connect, you subscribe to a single global channel with everyone else. Everything you send is broadcasted publically to the room. This makes it an End-to-End Encrypted (E2EE) messaging system utilizing a central Relay rather than a true Peer-To-Peer network.
2. RSA Mathematics & Key Generation
Cryptography relies on the computational difficulty of factoring large numbers. When you create a user, PyScript runs this logic locally in your browser:
Public Key: (n, e) is announced to the world.
Private Key: (d) stays perfectly secret inside your browser memory.
3. The Magic: Euler's Theorem
To encrypt a character payload m into a ciphertext c, Python does:
c ≡ me (mod n)
To decrypt c back to the character:
m ≡ cd (mod n)
This works perfectly because cd ≡ (me)d ≡ me·d (mod n). Since e · d ≡ 1 (mod φ(n)), Euler's theorem guarantees that the math wraps seamlessly back to the original message m.
4. Messaging Interception
Because the ciphertext is broadcasted to the entire WebSocket room, anyone can intercept it (as seen in your "Global Hub Network" tab). However, since only the recipient has the mathematically linked private key (d) that fits that equation, only their browser can decrypt the payload into readable text. For everyone else, it remains cryptographic noise.