Knapsack public key cryptosystem

The general knapsack problem can be stated as: Given a set of n weights, W1,W2,...,Wn, and a sum S, is it possible to find ai∈{0,1} such that

      S = a1W1+a2W2+...+ anWn

The general knapsack problem is NP-complete.

However, a superincreasing knapsack, i.e., a knapsack in which each weight is greater than the sum of all previous weights, is easy to solve.

A public key crpytosystem can be constructed based on the knapsack problem by

  1. Generate a superincreasing knapsack.
  2. Convert the superincreasing knapsack into a "general" knapsack by multiplying all of the numbers by n mod m, where m is greater than the sum of all of the numbers in the knapsack and the n has no factor in common with m.
  3. The superincreasing knapsack, together with m and n, is the private key.
  4. The corresponding general knapsack is the public key.
  5. It is easy to encrypt using the general knapsack; simply add all of the elements in the 1's positions.
  6. Given the private key, the ciphertext can be converted to a superincreasing knapsack, which is then easily solved to decrypt the message.
  7. Without the private key, an attacker must solve the "general" knapsack problem to recover the message.

Example (from Schneier): Let the private key be the superincreasing knapsack

     {2,3,6,13,27,52}

and choose

     n = 31 and m = 105

Then the general knapsack is computed as

     2⋅31 mod 105 = 62
     3⋅31 mod 105 = 93
     6⋅31 mod 105 = 81
     13⋅31 mod 105 = 88
     27⋅31 mod 105 = 102
     51⋅31 mod 105 = 37

and the public key is

     {62,93,81,88,102,37}.

To encrypt, say, 110101, we compute

      1⋅62 + 1⋅93 + 0⋅81 + 1⋅88 + 0⋅102 + 1⋅37 = 280.

To decrypt 280, we need the inverse of 31 mod 105, i.e., we need to find the number x such that 31x mod 105 = 1. Solving this, we find that x = 61. Then

     280⋅61 mod 105 = 70,

which we easily solve using the superincreasing knapsack to find the plaintext 110101.

Note: This knapsack scheme is insecure. Knapsack Cryptosystems: The Past and the Future is a nice article on the knapsack cryptosystem.