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
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.