# Post-Quantum Cryptography

Cryptographic algorithms designed to resist attack by future quantum computers, now being standardised.

**Rests on:** Modular Arithmetic

*Security and Privacy · Cryptography*


## Why learn this

This unlocks your ability to understand why the security of nearly every online transaction, encrypted message, and digital signature is being re-engineered right now. You will be able to read news about 'quantum-safe' standards, understand what a migration timeline means for companies, and eventually grasp the mathematics behind new security methods that rely on complex geometric grids. Mastering this concept is the foundation for studying specific algorithms that will replace the two most common encryption systems in the next few years: one called RSA, which secures data by multiplying huge numbers, and another called ECC, which secures connections using shapes on a curve. It connects directly to the study of Cryptographic Algorithms and Secure Infrastructure.


## The intuition

Think of today's cryptography as a lock. The lock is strong because it is mathematically very hard to pick. For example, a classic system, RSA, uses the fact that multiplying two large prime numbers is easy, but finding those primes from the product is incredibly difficult. Your computer can multiply two 300-digit numbers in a split second, but even a supercomputer would take longer than the age of the universe to work backwards from the product to the two original primes. That difficulty is the entire basis of the lock. Now imagine a brand-new kind of lock-picking tool, one that can try millions of billions of combinations at once. Not by being faster, but by working in a fundamentally different way — exploring all the combinations at the same time. If you gave this tool to a lock-picker, they could open a normal lock in minutes. That is what a large-scale quantum computer threatens to do to the locks we use today. Post-quantum cryptography is the design of new locks that this quantum lock-picker cannot open. It is not about making the same lock harder to pick; it is about inventing a different geometric principle that the quantum tool cannot exploit.


## An analogy

Imagine a key and a lock. The key has a specific, rugged shape. The lock has a set of pins inside that must be pushed to exactly the right heights to let the key turn. To unlock it without the key, you would have to try pushing all the pins to many different heights, one combination at a time. This is like with current RSA. Now imagine a lock-picker gets a magic device. Instead of trying one combination, the device can measure the lock in a way that reveals the result of trying all combinations at once — as if it could see the entire shadow of every possible key simultaneously. With this device, lock-picking is trivial. To make a lock for the age of the quantum lock-picker, you don't make smaller pins. You invent a completely different system: a lock with a maze of sliding blocks. There is no 'magic device' shortcut to navigate the maze; the only way to find the path is to walk through every twist and turn, even with the magic device. The maze is the lattice — a giant, irregular grid of points. The trick is a 'shortest path' problem in the maze. Giving one point in the maze, finding the exact shortest path back to the start is easy if you drew the maze (you have the secret key), but impossibly hard for anyone else, even with a quantum device. Post-quantum cryptography relies on this 'maze' being so tangled that no amount of parallel processing can shortcut it. This analogy works well, but it breaks down here: the quantum device doesn't just 'parallelly process' things faster, it uses the fundamental weirdness of quantum mechanics to 'see' many possibilities at once. But the core point stands — it's a completely different kind of hardness that the quantum computer cannot get a handle on.


## Definition

Post-quantum cryptography is the field of designing and standardising cryptographic algorithms that are believed to be secure against attacks from both classical and quantum computers, ensuring security for decades to come.


## How it connects

You are starting this from scratch, so you have no prior cryptographic knowledge to build on. Everything here is new. But it connects directly to the natural curiosity you have about how security works. It is the next chapter in the story of keeping secrets. Once you have a grasp of why we need new locks, you can start to learn about the special materials they are made of (lattices) and how they are used in day-to-day encryption, which is called Cryptographic Algorithms.


## The mathematics

The mathematics of post-quantum cryptography is not about difficult operations like calculus. It rests on a branch called discrete mathematics or, more specifically, linear algebra over finite structures. Don't worry about those names for now. The core operation is very simple arithmetic: adding and multiplying lists of numbers (called vectors). The 'hard problem' that makes the system secure is about distances between points in a massive, repeating grid. Imagine drawing a grid of all the points with integer coordinates, like (1,2), (1,3), (2,2), (10, 15), etc. This grid of points is called a lattice. The cryptographic trick is this: given one specific, very long vector, it is easy to compute the distance from it to the nearest point on the grid if you know the grid's 'basis' (a kind of secret map). But if you are only handed the grid itself, with millions of points and no map, it is computationally impossible to find the nearest point. This is called the 'Closest Vector Problem'. So, the public key is a badly described grid (the whole set of points). The private key is the neat, short map to your particular spot in the grid. To encrypt a message, a sender will use the public grid to 'hide' the message inside a random point far away in the grid. The owner with the secret map can easily find the nearest grid point and decode the message, but anyone else is totally lost. The mathematics is just addition and multiplication of numbers; the 'hardness' comes from the sheer number of possibilities when you have vectors with hundreds of numbers each, meaning the number of possible combinations is astronomically large.

The core operation is a dot product. If you have a vector of numbers **x** and a vector of numbers **w**, the dot product is (x₁ × w₁) + (x₂ × w₂) + (x₃ × w₃)... They combine to produce a single number. The 'hard problem' is not a single formula but a class of problems, the most famous being the Learning With Errors problem. You can think of it as: **public key = (A, B)** where **B = (A · S) + e**, and **A** is a public matrix (a table of numbers), **S** is the secret vector (the private key), and **e** is a tiny error vector. The matrix A and the result B are public, but recovering S from them is impossibly hard for both classical and quantum computers.


## A worked example

```
Let's create a tiny, simplified lattice in 1 dimension to see the core principle. We'll use a grid of just the integers. Let's say the 'secret basis' is the number 7. The public grid is all the multiples of 7: ..., -14, -7, 0, 7, 14, 21, ... (and so on).

Step 1: Public grid: 0, 7, 14, 21, 28, 35, ... (multiples of 7)   # The person who set the system knows the secret is 7. They publish the grid, which everyone can see.
Step 2: A sender wants to send the number 5, but hide it. They pick a random number, say 20, and add the message: 20 + 5 = 25.   # The sender uses the public grid to disguise the message. They add a random offset (20) to the message (5) to get the transmitted value (25).
Step 3: Receiver gets 25. With the secret map (7), they find the nearest multiple of 7 which is 28 (since 4*7=28).   # The secret map is the knowledge of the structure. The receiver easily finds the closest 'grid point' to the received number.
Step 4: Receiver subtracts the grid point from the received number: 28 - 25 = 3, which is 5 mod 7.   # The difference between the received number and the nearest grid point is the message. (We will not worry about the exact modular arithmetic for now; the idea is the receiver recovers the message 5).
Step 5: Attacker sees the number 25. They don't know the grid is multiples of 7. They see all numbers as possibilities.   # Without the secret map, the attacker has no easier way to find the nearest grid point than trying every possible grid spacing. In a real system with hundreds of numbers, this is impossible.

Result: The receiver decodes the message (5) easily because they have the 'short cut'. The attacker cannot, because they don't know the secret structure.
```


## From scratch, in Python

```python
# Demonstration of the concept with a tiny (insecure) example
# This is a demonstration of the LEARNING WITH ERRORS idea.

# 1. Create a small secret vector (this is the private key)
secret_s = [2, -1]

# 2. Create a small public matrix (this is the public lattice)
matrix_A = [[1, 3],
            [4, 2]]

# 3. The error vector (a tiny, secret random number)
error_e = [0, 1]

# 4. Compute the public vector B = (A dot S) + e
#   B[0] = (1*2 + 3*-1) + 0 = (2 - 3) + 0 = -1
#   B[1] = (4*2 + 2*-1) + 1 = (8 - 2) + 1 = 7

B = []
for row in matrix_A:
    # Dot product
    val = 0
    for i in range(len(secret_s)):
        val += row[i] * secret_s[i]
    # Add error
    val += error_e[len(B)]
    B.append(val)

print("Public matrix A:", matrix_A)
print("Public vector B:", B)
print("The secret vector S is: [2, -1]")
print("The error e is: [0, 1]")
print("")
print("If an attacker just sees A and B, it is hard to find S.")
print("But with S, you can check that A*S + e = B.")
```


## What the code does

First, we create the secret vector `secret_s`, which is the private key, and the public matrix `matrix_A`, which is a table of numbers that everyone can see. The `error_e` is a tiny amount of noise that is added on. The loop then computes the dot product of each row of `matrix_A` with the secret vector `secret_s`. For the first row, it multiplies 1 by 2 and 3 by -1, getting 2 and -3. Adding them gives -1, then we add the error 0, leaving -1. This is stored as the first element of B. For the second row, we get 8 - 2 = 6, plus the error 1, making 7. The message shows that if you have S, you can easily verify the public data; but if you only have A and B, finding S is the hard problem. In a real system, the matrix A and vector B are huge (hundreds of numbers) and the numbers are not small integers - they are numbers modulo a large prime. The 'hardness' is that guessing the secret S from a large, random-looking system is computationally infeasible.


## Common misconceptions

**Quantum computers are here, so I need to migrate now.** — A quantum computer powerful enough to break RSA exists right now, so I should panic and replace everything immediately.

A functional, large-scale quantum computer that can run Shor's algorithm is not yet available. The threat is real, but it is in the next decade. This is a 'race' but not a 'surprise attack' that will happen tomorrow. In fact: Threat is future but tangible, hence the urgency to plan and start migrating long-lived secrets now. There is time, but not infinite time.

**Post-quantum crypto is just bigger keys.** — To make my RSA secure from quantum computers, I just need to make the key size much larger, like 4096 bits or bigger.

The quantum algorithm is exponentially faster, not just a constant factor. Increasing the key size only makes a constant factor of difference; it doesn't close the exponential gap. In fact: Post-quantum algorithms use entirely different mathematical problems (lattices, hashes) that do not have known quantum algorithms with exponential speed-up.

**Post-quantum cryptography is just keeping the old stuff and changing the key.** — I can just keep using RSA/ECC and change the key generation or key exchange endpoint, and the rest stays the same.

The underlying mathematical hardness assumption is broken. To be safe, you need a fundamentally different mathematical problem for the core encryption or signature, but everyone in the ecosystem (from the CA, to the server, to the client) must understand it. In fact: Post-quantum is a migration of the *core algorithms*, not just a key-size tweak. Old protocols must be entirely replaced with new algorithms from the NIST list.

**The hardest part is the cryptography itself.** — Once the algorithms are standardised, everything is done and simple.

The hardest part is deployment: integrating the new algorithms into the internet's infrastructure (TLS, VPNs, etc.), ensuring compatibility with old devices, and testing for bugs. It is a logistics and re-engineering problem. In fact: The bottleneck is the inventory and replacement of every system that uses the old algorithms, a multi-year project for any large organisation.


## In short

Post-quantum cryptography is not about making current locks harder to pick—it's about inventing new locks that the quantum lock-pick gun can't open. The current locks (RSA, ECC) rely on factoring and discrete logarithms, which quantum computers can break. The new locks (lattices, hashes) rely on problems like finding a shortest path in a giant maze, which remain intractable even for quantum computers. The standardisation is done, the migration is the hard part.


## Where this is used

This concept is not directly used as a component inside machine learning models, large language models, or retrieval-augmented generation pipelines. Post-quantum cryptography is not a part of the model's architecture; it is a part of the security layer *around* the system. However, its importance is immense. When an AI system — an LLM chatbot, an image recognition service, a recommendation engine — needs to communicate with a client over the internet, the traffic is encrypted. That encryption will be built using post-quantum algorithms. For example, when your phone calls an LLM API, the TLS handshake to establish a secure connection will soon use a post-quantum key exchange (like Kyber) to protect against a 'harvest-now-decrypt-later' attack. In the world of small, edge-based AI (TinyML), the security of the model updates and parameters on a device uses digital signatures, which will similarly be replaced with post-quantum signatures (like Dilithium). The need is not specific to AI; it's for every piece of software. A developer building a secure AI application today would call a library such as `liboqs` (Open Quantum Safe), or use a messaging library that has already integrated these algorithms. They would write code like `client = OQSClient('Kyber768')` to use the new key exchange, or `` to use the new signature scheme. The subtle 'breakage' that happens if this is done badly is that a company might only upgrade the certificate chain, but not the internal key-agreement protocols, leaving an exploitable gap for a sophisticated attacker to harvest encrypted AI queries today and decrypt them in five years. The complexity of doing this well is why the migration is a multi-year inventory and replacement programme. In summary, the concept's application is *infrastructure*, not model internals.


---

Read this on the web: https://basavapurushottam.com/learn-ai/post-quantum-cryptography
