diff options
Diffstat (limited to '3544/CH2/EX2.42/Ex2_42.sce')
-rw-r--r-- | 3544/CH2/EX2.42/Ex2_42.sce | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/3544/CH2/EX2.42/Ex2_42.sce b/3544/CH2/EX2.42/Ex2_42.sce new file mode 100644 index 000000000..8281e7a56 --- /dev/null +++ b/3544/CH2/EX2.42/Ex2_42.sce @@ -0,0 +1,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))
+
|