summaryrefslogtreecommitdiff
path: root/3544/CH2/EX2.36/Ex2_36.sce
blob: dc6ae13ac87c53298bb1675be0f9a22dcbbe19c9 (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
//Rail fence 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)

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

ct = []
k=1

//Writing diagonally
for i=1:length(pt)
    if modulo(i,2)==0 then
        continue
    end
    ct(k,1) = part(pt,i:i)
    ct(k,2) = part(pt,i+1:i+1)
    k = k+1
end

ct = strcat(ct)
disp("")
disp("Ciphertext:")
disp(ct)