blob: 8281e7a565b3db987ddf48b76f81a6db67f1838f (
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
|
//Vernam cipher
// 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)
a= ascii('A')
pt = "HOW ARE YOU?" //Plaintext
disp("")
disp("Original plaintext:")
disp(pt)
//function from dependency file
pt = remove_spaces(pt) //Processed plaintext for encryption
disp("")
disp("Plaintext:")
disp(pt)
disp(ascii(pt)-a)
disp("")
disp("One-time pad:")
otp = "NCBTZQARX" //OTP
disp(otp)
disp(ascii(otp)-a)
ct = []
for i=1:length(pt) //Encryption stage
ct(i) = ascii(part(pt,i:i)) + ascii(part(otp,i:i)) -2*a
end
disp("")
disp("Initial total:")
disp(ct')
disp("")
disp("Subtracting 26 if >25")
ct = modulo(ct,26) //Taking modulo 26 to make range b/w 0-25
disp(ct')
ct = char(ct+a)' //Ciphertext
disp("")
disp("Ciphertext: ")
disp(strcat(ct))
|