summaryrefslogtreecommitdiff
path: root/3544/CH2/EX2.43/Ex2_43.sce
blob: 40dc463c12acdd207a483bad62630427fc5c28ff (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

//Encryption

// 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)

pt = "Hello John"

disp("Plain-text message:")
disp(pt)

a = ascii('a')
z = ascii('z')
A = ascii('A')
Z = ascii('Z')


ct = []
for i=1:length(pt(k))
    x = ascii(part(pt(k,1),i:i))
    if x>=A & x<=Z then
        //function from dependency file
        ct(k,i) = encrypt_caesar_general(part(pt(k),i:i),1)
    elseif x>=a & x<=z then
        c = convstr(part(pt(k),i:i),'u')
        c = encrypt_caesar_general(c,1)
        c = convstr(c,'l')
        ct(k,i) = c
    else
        ct(k,i) = part(pt(k),i:i)
    end
end

ct = strcat(ct)
disp("")
disp("Cipher text")
disp(ct)