diff options
Diffstat (limited to '3544/CH2/EX2.40/Ex2_40.sce')
-rw-r--r-- | 3544/CH2/EX2.40/Ex2_40.sce | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/3544/CH2/EX2.40/Ex2_40.sce b/3544/CH2/EX2.40/Ex2_40.sce new file mode 100644 index 000000000..224dbbab0 --- /dev/null +++ b/3544/CH2/EX2.40/Ex2_40.sce @@ -0,0 +1,69 @@ +//Example of simple columnar ransposition technique with multiple rounds
+
+// Move scilab to current file directory
+[u,t,n] = file()
+n = strcat(n)
+file_name = basename(n)+fileext(n)
+file_name = strcat(file_name)
+ind=strindex(n,file_name)
+path = part(n,1:ind-1)
+chdir(path)
+
+exec("Chapter_2.sci")
+
+pt = "Come home tomorrow"
+disp("Original plaintext message:")
+disp(pt)
+
+//function from dependency file
+l = length(remove_spaces(pt))
+//disp(l)
+
+rounds = 2
+col_order = [4 6 1 2 5 3]
+col = 6
+row = l/6
+ if modulo(l,6)>0 then
+ row=row+1
+ end
+
+for r=1:rounds
+ printf("\nRound %d:",r)
+
+ //function from dependency file
+ pt_mat = message_rectangle(pt)
+
+ disp("")
+ disp("Plaintext:")
+ disp(pt)
+ disp("Plaintext message rectangle:")
+ printf("\n")
+ for i=1:col
+ printf(" %d ",i)
+ end
+ disp(pt_mat)
+
+ k=1
+
+ ct=[]
+ //Convert to ciphertext
+ for n = 1:length(col_order)
+ j = col_order(n)
+ for i=1:row
+ pos = (i-1)*col + j
+ if pos>l then
+ continue
+ end
+ ct(k)=pt_mat(i,j)
+ k=k+1
+ end
+ end
+ disp("Ciphertext:")
+ ct = strcat(ct)
+ disp(ct)
+ pt = ct
+ disp("")
+end
+
+disp("Final ciphertext:")
+disp(ct)
|