Welcome back to Quantum For Devs.
If you read Part 1, you know that we absolutely refuse to use the “spinning coin” analogy to explain quantum computing here. If not, you can read by clicking this link and I do recommend reading Part 1 first.
We established that a classical bit is like a light switch (rigidly 0 or 1), while a quantum bit (qubit) is like a delicate, floating soap bubble. While it floats, it holds a continuous, beautiful blend of possibilities (superposition). But the moment you try to catch it to see what it is, it pops, collapsing into a single, flat drop of water (a classical 0 or 1).
That analogy is great for intuition. But as developers, intuition isn’t enough. We need to be able to map it, code it, and build software with it.
How exactly do you write code for a soap bubble?
Grab a coffee. Today, we are taking our bubble, turning it into a map, and writing the Python code to manipulate it.
Mapping the Bubble: The “Quantum Globe”
If you ask a physicist how to visualize a qubit, they will give you a terrifying mathematical construct called the Bloch Sphere.
It sounds intimidating, but it is actually just a globe. Think of the planet Earth.
If our qubit was a standard, boring classical bit, it would only be allowed to live in two places on this globe:
- The North Pole: We call this state 0.
- The South Pole: We call this state 1.
A classical bit is an airplane that can only teleport instantly between the North Pole and the South Pole. It cannot exist anywhere else.
But our quantum soap bubble? It can float anywhere on the surface of the entire planet.
- If the bubble is floating in New York, it has a certain probability of snapping to the North Pole (0) when measured.
- If the bubble is floating in Buenos Aires, it is much closer to the bottom, so it is highly likely to snap to the South Pole (1) when measured.
The Equator: Perfect Superposition
What happens if we place our bubble exactly on the Equator (let’s say, floating over Ecuador)?
It is exactly halfway between the North Pole (0) and the South Pole (1).
If you measure the bubble while it is on the equator, the universe literally flips a coin. You have a mathematically perfect 50% chance of getting a 0, and a 50% chance of getting a 1.
This “Equator State” is the purest form of quantum superposition.
How Do We Move the Bubble? (Quantum Gates)
In classical programming, if we want to change a 0 to a 1, we use a NOT gate.
In quantum programming, we use Quantum Gates to physically rotate our bubble around the globe. And the most famous, most important quantum gate in existence is called the Hadamard Gate (or H-Gate).
Think of the H-Gate as a magical gust of wind.
If your bubble is sitting at the North Pole (0), applying an H-Gate blows the bubble exactly 90 degrees down to the Equator.
This exact movement is the foundation of Quantum Key Distribution (QKD). When Alice wants to send a secure password to Bob, she doesn’t just send standard 0s and 1s. She uses quantum gates to randomly hide her data either on the Poles (Z-basis) or on the Equator (X-basis).
If an eavesdropper tries to look at a bubble on the equator with a “North Pole” telescope, the bubble pops incorrectly, creating an error that Alice and Bob instantly detect.
Let’s Prove it With Python
Let’s look at how this works in real software.
If you haven’t already, you can install my open-source QKD library, qkdpy, which simulates these exact physical states to generate unhackable keys.
pip install qkdpy
Under the hood of BB84 (the most famous quantum security protocol), Alice is essentially playing a game of hide-and-seek on the Bloch Sphere (The Globe). Here is the pseudo-code for how she prepares her quantum states:
import random
# Alice has a classical bit she wants to send securely
classical_bit = 1
# She flips a coin to choose whether to put the bubble on the Poles or the Equator
use_equator = random.choice([True, False])
if not use_equator:
# Z-Basis: Leave it at the Poles!
# If bit is 0 -> North Pole. If bit is 1 -> South Pole.
qubit_position = "North Pole" if classical_bit == 0 else "South Pole"
print(f"Alice encoded the bubble at the {qubit_position}")
else:
# X-Basis: Move it to the Equator using our "Quantum Wind" (H-Gate)
# If bit is 0 -> Equator Front. If bit is 1 -> Equator Back.
qubit_position = "Equator Front" if classical_bit == 0 else "Equator Back"
print(f"Alice applied an H-Gate! Bubble is at the {qubit_position}")
When Alice sends an “Equator” bubble over the fiber optic cable, the hacker (Eve) has no idea if she should try to catch it at the Poles or the Equator. If Eve guesses wrong, she permanently alters the bubble’s coordinates.
When Bob receives it, he checks the coordinates. If they moved, he knows Eve is listening.
The Math (I Promise It’s Easy)
I said no dense math, and I mean it. But you should know what a quantum state looks like in an array, because you will see it in every quantum SDK (like Qiskit, Cirq, or qkdpy).
Instead of just 0 or 1, a qubit’s state is written as a simple 2D array (a list with two numbers):
[North_Probability, South_Probability]
(Technically, these are complex amplitudes, but let’s keep it simple for today).
- North Pole (State 0): [1, 0]
- South Pole (State 1): [0, 1]
- Equator (Superposition): [0.707, 0.707]
Wait, why 0.707?
Because in quantum mechanics, the probabilities are squared. And
(0.707)² ≈ 0.5
So, a 50% chance of being 0, and a 50% chance of being 1!
Boom. You just did quantum linear algebra.
What We Learned Today
- The Bloch Sphere is just a globe where the Poles are 0 and 1, and the rest of the surface is a superposition.
- The Hadamard Gate (H-Gate) is the wind that blows a qubit from the Poles to the Equator.
- We code qubits using simple 2D lists (state vectors) instead of single binary numbers.
Next Up: Spooky Action 👻
In Part 3, we are going to tackle the most mind-bending concept in physics: Quantum Entanglement. What happens when two soap bubbles are magically linked across thousands of miles?
Until then, I’d love it if you dropped a star on the qkdpy GitHub Repository.
Pranava-Kumar
/
qkdpy
"Enterprise-grade Quantum Key Distribution (QKD) simulation library for Python. Supports BB84, E91, CV-QKD, and Quantum Networks. Secure, typed, and ML-optimized."
QKDpy: Quantum Key Distribution Library
A Python library for Quantum Key Distribution simulation at the intersection of Space Technology, Quantum Computing, AI/ML, and config audit tooling
⚠️ This is a simulation / educational library, not a production cryptographic system. QKDpy models QKD protocols, channels, and attacks with phenomenological approximations. It is not validated for securing real key material, and its channel/noise/error-correction models are simplified. Do not use it to generate or protect production secrets. See Status & Scope for the precise maturity level.
Features • Status & Scope • Satellite QKD • ML Integration • Observability • Product Tiers • Quantum-Safe Migration • Quick Start
🏗️ Architecture Overview
Detailed architecture diagrams are available in
docs/diagrams/. Each diagram below is a high-level summary — click through to the linked file for full detail.
High-Level Module Architecture
The system is organized into 9 modular layers. Arrows represent dependency direction.
Open-source thrives on community support, and if you want to poke around the actual Python code simulating these globes and gates, that is the place to be!
👇 Let’s chat in the comments: Did the Globe analogy make the Bloch Sphere click for you? What programming languages are you currently writing your day-to-day code in?

Top comments (0)