summaryrefslogtreecommitdiff
path: root/3544/CH4/EX4.62/Ex4_62.sce
blob: 787468cedcb486bc0538f61fe03da098782154d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Knapsack algorithm for Public Key Encryption

PT = [0 1 1 0 1 1; 1 1 1 0 0 0; 0 1 0 1 1 0]

disp("Plain text")
disp(PT)

K = [1 7 8 12 14 20]
disp("Knapsack:")
disp(K)

[row,col] = size(PT)
C = []
for i=1:row
    sum=0
    for j=1:col
        sum = sum+PT(i,j)*K(j:j)
    end
    C(i:i) = sum
end

disp("Cipher text:")
disp(C)