diff options
author | prashantsinalkar | 2017-10-10 12:27:19 +0530 |
---|---|---|
committer | prashantsinalkar | 2017-10-10 12:27:19 +0530 |
commit | 7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch) | |
tree | dbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /3544/CH6/EX6.54/Ex6_54.sce | |
parent | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff) | |
download | Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2 Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip |
initial commit / add all books
Diffstat (limited to '3544/CH6/EX6.54/Ex6_54.sce')
-rw-r--r-- | 3544/CH6/EX6.54/Ex6_54.sce | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/3544/CH6/EX6.54/Ex6_54.sce b/3544/CH6/EX6.54/Ex6_54.sce new file mode 100644 index 000000000..6e76847b4 --- /dev/null +++ b/3544/CH6/EX6.54/Ex6_54.sce @@ -0,0 +1,55 @@ +
+//Base 64 encoding example
+
+[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)
+
+//Get function to create encoding table
+exec("Chapter_6.sci",-1)
+
+enc = encoding_table()
+
+inp = "001000110101110010010001" // Input
+disp("24-bit input:")
+disp(inp)
+disp("")
+dec = []
+
+for i=1:length(inp)/6 //Convert to 6-bit packets stored as
+ str = part(inp,((i-1)*6+1):((i-1)*6+6)) //integers
+ dec(i)=0
+ for j=1:length(str)
+ if part(str,j:j)=='1' then
+ dec(i) = dec(i)+2^(6-j)
+ end
+ end
+end
+
+disp("Divided into 6-bit blocks:")
+disp(dec2bin(dec'))
+disp("")
+
+disp("Decimal equivalents:")
+disp(dec') //Decimal equivalents
+disp("")
+dec_str = []
+
+for i=1:length(dec)
+ dec_str(i) = (ascii(enc(dec(i)+1)))
+end
+
+disp("Map to base-64 encoding table (shown in Fig. 6.55):")
+disp(dec_str') //Character values from encoding table
+disp("")
+dec_str = ascii(dec_str)
+
+bin_str = dec2bin(dec_str) //Convert to ASCII binary
+bin_str = string(bin_str)
+bin_str = '0'+bin_str //Convert to 8-bit from 7-bit
+disp("ASCII equivalent binary")
+disp(bin_str)
|