The Merkle–Hellman knapsack cryptosystem was one of the earliest public key cryptosystems. It was published by Ralph Merkle and Martin Hellman in 1978. A polynomial time attack was published by Adi Shamir in 1984. As a result, the cryptosystem is now considered insecure.[1] [2]
The concept of public key cryptography was introduced by Whitfield Diffie and Martin Hellman in 1976.[3] At that time they proposed the general concept of a "trap-door one-way function", a function whose inverse is computationally infeasible to calculate without some secret "trap-door information"; but they had not yet found a practical example of such a function. Several specific public-key cryptosystems were then proposed by other researchers over the next few years, such as RSA in 1977 and Merkle-Hellman in 1978.[4]
Merkle–Hellman is a public key cryptosystem, meaning that two keys are used, a public key for encryption and a private key for decryption. It is based on the subset sum problem (a special case of the knapsack problem).[5] The problem is as follows: given a set of integers
A
c
A
c
A
In Merkle–Hellman, decrypting a message requires solving an apparently "hard" knapsack problem. The private key contains a superincreasing list of numbers
W
B
W
B
W
Unlike some other public key cryptosystems such as RSA, the two keys in Merkle-Hellman are not interchangeable; the private key cannot be used for encryption. Thus Merkle-Hellman is not directly usable for authentication by cryptographic signing, although Shamir published a variant that can be used for signing.[6]
1. Choose a block size
n
n
2. Choose a random superincreasing sequence of
n
W=(w1,w2,...,wn)
The superincreasing requirement means that
wk>
k-1 | |
\sum | |
i=1 |
wi
1<k\len
3. Choose a random integer
q
q>
n | |
\sum | |
i=1 |
wi
4. Choose a random integer
r
\gcd(r,q)=1
r
q
5. Calculate the sequence
B=(b1,b2,...,bn)
where
bi=rwi\bmodq
The public key is
B
(W,q,r)
Let
m
n
m1m2...mn
m1
bi
mi
c=
n | |
\sum | |
i=1 |
mibi
c
To decrypt a ciphertext
c
B
c
W
W
1. Calculate the modular inverse of
r
q
r
q
r':=r-1\pmodq
The computation of
r'
2. Calculate
c':=cr'\bmodq
3. Solve the subset sum problem for
c'
W
X=(x1,x2,...,xk)
W
c'
c'=
k | |
\sum | |
i=1 |
w | |
xi |
4. Construct the message
m
xi
m=
k | |
\sum | |
i=1 |
n-xi | |
2 |
This simple greedy algorithm finds the subset of a superincreasing sequence
W
c'
1. Initialize
X
2. Find the largest element in
W
c'
wj
3. Subtract:
c':=c'-wj
4. Append
j
X
5. Remove
wj
W
6. If
c'
Create a key to encrypt 8-bit numbers by creating a random superincreasing sequence of 8 values:
W=(2,7,11,21,42,89,180,354)
q
q=881
r
q
r=588
Construct the public key
B
W
r
q
\begin{align} &(2*588)\bmod881=295\\ &(7*588)\bmod881=592\\ &(11*588)\bmod881=301\\ &(21*588)\bmod881=14\\ &(42*588)\bmod881=28\\ &(89*588)\bmod881=353\\ &(180*588)\bmod881=120\\ &(354*588)\bmod881=236 \end{align}
Hence
B=(295,592,301,14,28,353,120,236)
Let the 8-bit message be
m=97=011000012
B
c
To decrypt 1129, first use the Extended Euclidean Algorithm to find the modular inverse of
r
q
r'=r-1\bmodq=588-1\bmod881=442
Compute
c'=cr'\bmodq=1129*442\bmod881=372
Use the greedy algorithm to decompose 372 into a sum of
wi
\begin{align} c'&=372\\ &w8=354\le372\\ c'&=372-354=18\\ &w3=11\le18\\ c'&=18-11=7\\ &w2=7\le7\\ c'&=7-7=0 \end{align}
372=354+11+7=w8+w3+w2
X=(8,3,2)
m=
3 | |
\sum | |
i=1 |
n-xi | |
2 |
=28-8+28-3+28-2=1+32+64=97
In 1984 Adi Shamir published an attack on the Merkle-Hellman cryptosystem which can decrypt encrypted messages in polynomial time without using the private key. [7] The attack analyzes the public key
B=(b1,b2,...,bn)
u
m
(ubi\bmodm)
(u,m)
(r',q)
B
Shamir's attack on the Merkle-Hellman cryptosystem works in polynomial time even if the numbers in the public key are randomly shuffled, a step which is usually not included in the description of the cryptosystem, but can be helpful against some more primitive attacks.