summaryrefslogtreecommitdiff
path: root/3544/CH4/EX4.62/Ex4_62.sce
diff options
context:
space:
mode:
Diffstat (limited to '3544/CH4/EX4.62/Ex4_62.sce')
-rw-r--r--3544/CH4/EX4.62/Ex4_62.sce23
1 files changed, 23 insertions, 0 deletions
diff --git a/3544/CH4/EX4.62/Ex4_62.sce b/3544/CH4/EX4.62/Ex4_62.sce
new file mode 100644
index 000000000..787468ced
--- /dev/null
+++ b/3544/CH4/EX4.62/Ex4_62.sce
@@ -0,0 +1,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)