Merkle–Hellman knapsack cryptosystem

From Wikipedia
Jump to navigation Jump to search

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]: 465  [2]: 190 

History

[edit]

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]

Description

[edit]

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   and an integer  , find a subset of   which sums to  . In general, this problem is known to be NP-complete. However, if   is superincreasing, meaning that each element of the set is greater than the sum of all the numbers in the set lesser than it, the problem is "easy" and solvable in polynomial time with a simple greedy algorithm.

In Merkle–Hellman, decrypting a message requires solving an apparently "hard" knapsack problem. The private key contains a superincreasing list of numbers  , and the public key contains a non-superincreasing list of numbers  , which is actually a "disguised" version of  . The private key also contains some "trapdoor" information that can be used to transform a hard knapsack problem using   into an easy knapsack problem using  .

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]

Key generation

[edit]
  1. Choose a block size  . Integers up to   bits in length can be encrypted with this key.
  2. Choose a random superincreasing sequence of   positive integers Template:Bi The superincreasing requirement means that  , for  .
  3. Choose a random integer   such that Template:Bi
  4. Choose a random integer   such that   (that is,   and   are coprime).
  5. Calculate the sequence Template:Bi where  .

The public key is   and the private key is  .

Encryption

[edit]

Let   be an  -bit message consisting of bits  , with   the highest order bit. Select each   for which   is nonzero, and add them together. Equivalently, calculate Template:Bi The ciphertext is  .

Decryption

[edit]

To decrypt a ciphertext  , we must find the subset of   which sums to  . We do this by transforming the problem into one of finding a subset of  . That problem can be solved in polynomial time since   is superincreasing.

  1. Calculate the modular inverse of   modulo   using the Extended Euclidean algorithm. The inverse will exist since   is coprime to  . Template:Bi The computation of   is independent of the message, and can be done just once when the private key is generated.
  2. Calculate Template:Bi
  3. Solve the subset sum problem for   using the superincreasing sequence  , by the simple greedy algorithm described below. Let Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle X=(x_{1},x_{2},\dots ,x_{k})} be the resulting list of indexes of the elements of Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle W} which sum to Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c'} . (That is, Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c'=\sum _{i=1}^{k}w_{x_{i}}} .)
  4. Construct the message Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle m} with a 1 in each Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle x_{i}} bit position and a 0 in all other bit positions: Template:Bi

Solving the subset sum problem

[edit]

This simple greedy algorithm finds the subset of a superincreasing sequence Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle W} which sums to Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c'} , in polynomial time:

  1. Initialize Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle X} to an empty list.
  2. Find the largest element in Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle W} which is less than or equal to Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c'} , say Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle w_j} .
  3. Subtract: Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c' := c' - w_j} .
  4. Append Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle j} to the list Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle X} .
  5. Remove Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle w_j} from the superincreasing sequence Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle W}
  6. If Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c'} is greater than zero, return to step 2.

Example

[edit]

Key generation

[edit]

Create a key to encrypt 8-bit numbers by creating a random superincreasing sequence of 8 values: Template:Bi The sum of these is 706, so select a larger value for Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle q} : Template:Bi Choose Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle r} to be coprime to Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle q} : Template:Bi

Construct the public key Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle B} by multiplying each element in Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle W} by Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle r} modulo Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle q} :

Template:Bi

Hence Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle B = ( 295, 592, 301, 14, 28, 353, 120, 236 )} .

Encryption

[edit]

Let the 8-bit message be Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle m = 97 = 01100001_2} . We multiply each bit by the corresponding number in Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle B} and add the results:

  0 * 295
+ 1 * 592
+ 1 * 301
+ 0 * 14
+ 0 * 28
+ 0 * 353
+ 0 * 120
+ 1 * 236
    = 1129

The ciphertext Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c} is 1129.

Decryption

[edit]

To decrypt 1129, first use the Extended Euclidean Algorithm to find the modular inverse of Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle r} mod Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle q} : Template:Bi

Compute Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c' = c r' \bmod q = 1129*442 \bmod 881 = 372} .

Use the greedy algorithm to decompose 372 into a sum of Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle w_i} values: Template:Bi Thus Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 372 = 354 + 11 + 7 = w_8 + w_3 + w_2} , and the list of indexes is Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle X = (8,3,2)} . The message can now be computed as Template:Bi

Cryptanalysis

[edit]

TemplateStyles' src attribute must not be empty.

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 Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle B = (b_1, b_2, \dots, b_n)} and searches for a pair of numbers Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle u} and Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle m} such that Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle (u b_i \bmod m)} is a superincreasing sequence. The Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle (u,m)} pair found by the attack may not be equal to Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle (r',q)} in the private key, but like that pair it can be used to transform a hard knapsack problem using Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle B} into an easy problem using a superincreasing sequence. The attack operates solely on the public key; no access to encrypted messages is necessary.

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.


In 2025, Bi presented an improved algorithm that recovers a partial super-increasing sequence as an equivalent private key. By applying the LLL algorithm to a specially constructed small-dimension lattice, they recover the plaintext in under one second on a standard laptop. [8]

References

[edit]
  1. Schneier, Bruce (1996). Applied Cryptography. New York: John Wiley & Sons. ISBN 0-471-12845-7.
  2. Stinson, Douglas R. (1995). Cryptography: Theory and Practice. Boca Raton: CRC Press. ISBN 0-8493-8521-0.
  3. Whitfield Diffie; Martin Hellman (1976). "New directions in cryptography". IEEE Transactions on Information Theory. 22 (6): 644. CiteSeerX 10.1.1.37.9720. doi:10.1109/TIT.1976.1055638.
  4. Merkle, Ralph; Hellman, Martin (1978). "Hiding information and signatures in trapdoor knapsacks". IEEE Transactions on Information Theory. 24 (5): 525–530. doi:10.1109/TIT.1978.1055927.
  5. Cherowitzo, William (2002-03-02). "Merkle-Hellman Knapsack Cryptosystem". Math 5410 - Modern Cryptology. Retrieved 2019-08-18.
  6. Shamir, Adi (July 1978). "A Fast Signature Scheme". MIT Laboratory for Computer Science Technical Memorandum. 79 (MIT/LCS/TM–107): 15240. Bibcode:1978STIN...7915240S.
  7. Shamir, Adi (1984). "A polynomial-time algorithm for breaking the basic Merkle - Hellman cryptosystem". IEEE Transactions on Information Theory. 30 (5): 699–704. doi:10.1109/SFCS.1982.5.
  8. Bi, Jingguo (May 28, 2025). "A simple and efficient attack on the Merkle-Hellman knapsack cryptosystem". PLoS One. doi:10.1371/journal.pone.0322726. PMC 12118879 Check |pmc= value (help). PMID 40435178 Check |pmid= value (help). Retrieved 14 March 2026.

Template:Cryptography navbox