blob: 224dbbab0d4cafc4bda19b980de0d269226a49f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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)
|