summaryrefslogtreecommitdiff
path: root/3544/CH2/EX2.38/Ex2_38.sce
blob: 2398a0efb19ce3a8dd43f11a3ed7c95a222562e0 (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
//Example of simple columnar ransposition technique

// 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",-1)

disp("Original plaintext message:")
pt = "Come home tomorrow"
disp(pt)
disp("")

//function from dependency file
pt = remove_spaces(pt)              

l = length(pt)

col = 6

row = l/6
    if modulo(l,6)>0 then
        row=row+1
    end

//Conversion of plaintext into a message table
//function from dependency file
pt_mat = message_rectangle(pt,col)

disp("Plaintext message rectangle:")
printf("\n")
for i=1:col
    printf(" %d ",i)
end
disp(pt_mat)
disp("")

//Column read order
col_order = [4 6 1 2 5 3]
disp("Column order: ")
disp(col_order)
disp("")
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)