Sitemap

🪄How to Break the Internet with Quantum Voodoo: A Fun Guide to Shor’s Algorithm

6 min readOct 26, 2026

--

Press enter or click to view image in full size

In today’s world, the super-secure password that you use has RSA encryption. But wait! Let’s take a look at what is it actually. RSA (Rivest-Shamir-Adleman) is a public-key cryptosystem that uses a pair of keys: a public key to encrypt data and a private key to decrypt it. A user can share their public key with anyone, but the private key is kept secret, ensuring only the intended recipient can read the message. The security of RSA relies on the computational difficulty of factoring the product of two very large prime numbers. Just look into it yourself, you will understand how quantum voodoo can do it’s trick….✌️

The Connection to Quantum Computing

This is where your interest in quantum computing becomes highly relevant. The entire security of RSA hinges on the assumption that factoring the large number n back into p and q is practically impossible for classical computers. If an attacker could figure out p and q, they could easily calculate your private key d and read all your messages.

Back in 1994, a guy named Peter Shor basically invented that calculator, and the entire world of cryptography collectively panicked. Shor’s Algorithm is the legendary quantum spell that threatens to turn the internet’s toughest security into a wet paper bag. Then there’s its cousin, Grover’s Algorithm, the ultimate “Where’s Waldo?” champion.

Today, we’re diving into these two titans of quantum computing. Don’t worry, we’ll keep the existential dread to a minimum, the memes to a maximum, and we’ll even write some code to prove this isn’t just science fiction.

Algorithms!

An algorithm is basically a recipe that a computer follows, telling it the precise steps to accomplish a task. Think of it as giving instructions to a genie who is incredibly powerful and fast, but has absolutely no common sense and will do exactly what you said, even if it means ordering 5,000 tubs of ice cream instead of one. So, now let’s look at the titans…

Shor’s Algorithm — The Crypto Killer

Now, imagine the modern era encryption to be like a giant, unbreakable piggy-bank, which as you know is based on RSA encryption. Breaking into this encryption via classical computing is very complicated and will take time until the heat death of universe, guess it’s too long of a time!

Hold on onto your seatbelts guys, the magic you want to witness will be performed by one the titans; Shor’s Algorithm….HAHAHAHA! (i guess, too quirky…😴).

It is so magical that just by tapping the ‘unbreakable piggy-bank’, it will crumble away like Thanos snapping his fingers! Too overpowered.👽

1. The Goal: Factor a Big, Beefy Number N

Our mission, should we choose to accept it: take a number like N=15 and find its secret ingredients (3 and 5). Except, in the real world, N has more digits than your daddy’s phone number, your daddy’s bank account, and your daddy’s social security number combined(intentionally non-intentional😉).

Get Aryan Sinha’s stories in your inbox

Join Medium for free to get updates from this writer.

Peeps, just look at the following flowchart to understand how actually RSA encryption works;

Press enter or click to view image in full size

NOTE: Mind it, the prime numbers, p and q are very large prime numbers, which takes a lot of computing power via classical way to decrypt it. How old-fashioned, hmmm!😒

2. The Secret Sauce: It’s All About Finding a Vibe (aka The Period)

Let’s just have a look at the Mathematics for this algorithm……..WAIT FELLAS, don’t go just yet!……. Let’s have a look in layman’s term.😉

No traps here…..i guess :D

Classically, this is where things get tough, hence, Quantum computer fires up and prepares it furnace using Quantum Fourier Transform (QFT) to find the rhythm. I have tried to simplify this as much as possible so that, me dearests can understand them….✌️

Part-1: Classical Reduction:

The algorithm’s first piece of genius is classical. It transforms the hard problem of factoring into an entirely different, but equivalent, problem: finding the period of a special function. If you can solve the period-finding problem, you can solve the factoring problem.

Press enter or click to view image in full size

Part-2: The Quantum Leap:

Finding the period ‘r’ is computationally impossible for large N on a classical computer. This is where the quantum computer takes over, performing this single, critical task with incredible efficiency.

Press enter or click to view image in full size
Press enter or click to view image in full size

The pre-requisite knowledge for Modular Exponentiation is required, see the following snippet to understand what and how this function works:

We’ll use Python and IBM’s Qiskit library, which is like a spell book for quantum programmers. The full Shor’s algorithm is a beast to write from scratch, but lucky for us, Qiskit has a high-level version we can use to taste its power. You will get know about Qiskit in the further Blogs, Stay tuned!😎

import qiskit
from qiskit.algorithms import Shor
from qiskit.utils import QuantumInstance

# --- The Setup ---
# The number we want to factor (let's stick to our example)
N = 15
print(f"Attempting to factor N = {N}")

# We need a quantum backend. For now, we'll use a local simulator.
# It's like a magical practice cauldron that pretends to be a quantum computer.
backend = qiskit.Aer.get_backend('qasm_simulator')
quantum_instance = QuantumInstance(backend, shots=1024)

# --- The Spell ---
# Create a Shor's algorithm instance.
# Qiskit handles all the ridiculously complex quantum circuit creation for us.
shors_algorithm = Shor(quantum_instance=quantum_instance)

# --- Cast the Spell! ---
# Run the algorithm and get the result.
result = shors_algorithm.factor(N)

# --- The Revelation ---
# The universe (or our simulator) whispers back the answer.
print(f"The factors of {N} are: {result.factors[0]}")

Run that code, and after a moment of simulated quantum thinking, it will spit out The factors of 15 are: [3, 5]. Spooky, right?

4. The “Yeah, But…” Section

So, is your data safe? For now, yes. Building a quantum computer that can run Shor’s for a number big enough to break RSA-2048 would require millions of stable, high-quality qubits. Running the code above on a simulator for a big number would make your laptop melt.

Quantum computers in 2025 trying to factor your bank password…

Conclusion

Shor’s algorithm is like that friend who shows up at a party, looks at a 300-digit number, and casually says, “Oh, that’s just 17 times 352…” while the rest of us are still struggling to divide pizza slices evenly. 🍕

On the serious side, it’s a reminder that quantum computers aren’t just faster calculators — they change the rules of the game. For cryptography, that means RSA and other classical systems may one day look about as secure as locking your diary with a plastic toy padlock. 🔒➡️😂

So, while classical computers sweat factoring big numbers, quantum computers (with Shor’s in their toolkit) are basically sitting back with popcorn, enjoying the show. The moral? Better start inventing post-quantum cryptography before Shor steals the spotlight completely.

Press enter or click to view image in full size

So, guys to learn Shor’s Algorithm in depth, read the recommended books so that you can understand the maths behind it all. Peace!✌️

Additional Resources:

Modular Exponentiation: https://www.math.wichita.edu/discrete-book/section-numtheory-modularexp.html

--

--

Aryan Sinha
Aryan Sinha

Machine Learning Enthusiast||MLOps||Quantum Computing Enthusiast||Langchain|| More things loading...