On this page
This early public-key scheme uses only multiplication, addition and remainders, so you can run it with a pencil. How it failed teaches as much as how it works.
What is the Merkle–Hellman knapsack cryptosystem?
The Merkle–Hellman knapsack cryptosystem is a public-key scheme in which a message is encrypted as a sum of chosen numbers from a public list, and only the owner of a secret key can tell which numbers were chosen. Ralph Merkle and Martin Hellman published it as Hiding information and signatures in trapdoor knapsacks in IEEE Transactions on Information Theory, volume 24, in 1978.
It rests on the subset sum problem: given a list of integers and a target, find a subset that adds up to the target. In general this problem is NP-complete (Wikipedia), so no fast method is known for every list. The trick is to make one special list that is easy, then disguise it.
Why is a superincreasing knapsack easy to solve?
A sequence is superincreasing when each term is bigger than the sum of all the terms before it, for example 3, 5, 11, 20, 41, 83, 167, 334. For such a list, subset sum is solved by a greedy method: take the largest term that fits, subtract it, repeat (Wikipedia).
Compare the general 0/1 knapsack worked with dynamic programming, which needs a whole table of choices.
How do you encrypt and decrypt a byte by hand?
Here is a full example with our own small numbers. Real keys use far longer lists.
Key generation (private).
Pick the superincreasing list W = (3, 5, 11, 20, 41, 83, 167, 334). Its sum is 664.
Pick a modulus q larger than that sum: q = 701.
Pick a multiplier r with no common factor with q: r = 233.
Multiply each term by 233 and take the remainder mod 701. This gives the public key B = (699, 464, 460, 454, 440, 412, 356, 11).
B no longer looks superincreasing: 699 comes first and 11 last. You publish B and keep W, q and r secret.
Encryption (anyone can do it). The letter F is 70 in ASCII, which is 01000110 in binary. Counting from the left, the 1s are in positions 2, 6 and 7, so add those entries of B: 464 + 412 + 356 = 1232. The ciphertext is 1232.
Decryption (only the key holder).
Find the inverse of 233 mod 701 with the extended Euclidean algorithm: 701 = 3 × 233 + 2 and 233 = 116 × 2 + 1, which unwinds to 1 = 349 × 233 − 116 × 701. So the inverse is 349.
Undo the disguise: 1232 × 349 mod 701 = 255.
Solve greedily in W: 334 is too big; take 167 (88 left); take 83 (5 left); skip 41, 20, 11; take 5 (0 left).
The terms used are positions 2, 6 and 7, so the bits are 01000110, which is 70, the letter F.
Multiplying by 349 cancels the 233, and because q exceeds the sum of W, the remainder is exactly 5 + 83 + 167.
How did Shamir break it in 1982?
Adi Shamir presented A polynomial time algorithm for breaking the basic Merkle-Hellman cryptosystem at the 23rd Symposium on Foundations of Computer Science in November 1982, with a journal version in IEEE Transactions on Information Theory in 1984. The attack uses only the public key: it searches for a multiplier and modulus that turn B back into some superincreasing list, not necessarily the owner's W, which is enough to decrypt (Wikipedia).
Later attacks use lattices. The LLL lattice reduction algorithm, published by Lenstra, Lenstra and Lovász in 1982, is still used against the scheme: a 2025 paper in PLOS ONE runs LLL on a small lattice and reports recovering the whole plaintext in under one second on a laptop for typical Merkle–Hellman parameters.
The modular disguise looked random, but it kept enough pattern for an attacker to find. If lattices are new to you, Minkowski's theorem on lattice points is a good next read.
How can you practise this yourself?
Build your own key with a different superincreasing list of 8 numbers, a prime q above its sum, and any r from 2 to q − 1.
Encrypt the first letter of your name, then swap ciphertexts with a friend who has only your public key.
Try greedy on B itself with 1232 and watch it fail.
To revise the ideas underneath, modular inverses, the Euclidean algorithm and subset sum, the Fermi Concept Library covers concepts across mathematics and computing. When you want to check your own working on a modular arithmetic problem, the Fermi Problem Library has a step-by-step solver that explains the reasoning rather than printing an answer.



