diff options
author | prashantsinalkar | 2019-05-08 11:47:37 +0530 |
---|---|---|
committer | prashantsinalkar | 2019-05-08 11:47:37 +0530 |
commit | 38b19b5aef8266b5e7e66e8dea164c6c9479e2ab (patch) | |
tree | 620e3d1141880f992bdf9cf0b1b0d6bc7927fc26 | |
parent | da8b74319eda501ba1d72f168122d55bbc4967f0 (diff) | |
download | Scilab-TBC-Uploads-1-38b19b5aef8266b5e7e66e8dea164c6c9479e2ab.tar.gz Scilab-TBC-Uploads-1-38b19b5aef8266b5e7e66e8dea164c6c9479e2ab.tar.bz2 Scilab-TBC-Uploads-1-38b19b5aef8266b5e7e66e8dea164c6c9479e2ab.zip |
initial commit / add all books
110 files changed, 4575 insertions, 0 deletions
diff --git a/3903/CH10/EX10.1/Ex10_1.sce b/3903/CH10/EX10.1/Ex10_1.sce new file mode 100644 index 000000000..b044fdb86 --- /dev/null +++ b/3903/CH10/EX10.1/Ex10_1.sce @@ -0,0 +1,15 @@ +
+// Chapter No : 10 Exercise Number : 10.1 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---trapdoor one way functon---
+clc;
+clear;
+printf("This example shows that the message length limitation of SHA-512 is not a serious problem. \nA communication network that can send 2^64 bits per second is not yet available Even if it were, it would take many years to send this message. This tells us tat we do not need to worry about the SHA-512 message length restriction");
diff --git a/3903/CH10/EX10.10/Ex10_10.sce b/3903/CH10/EX10.10/Ex10_10.sce new file mode 100644 index 000000000..45429fc51 --- /dev/null +++ b/3903/CH10/EX10.10/Ex10_10.sce @@ -0,0 +1,36 @@ +// Chapter No : 10 Exercise Number : 10.10 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---Elgamal Algorithm to develop ciphertext and plaintext---
+clc;
+clear;
+printf("\n-----------Ex10.10-----------");
+//Bob chooses the value of a large prime number p and e1- encryption key 1
+p=11;
+e1=2;//2 is a premitive root of Z-11
+//Bob chooses the value of decryption key
+d=3;
+//encryption key e2 is calculated using e1 and d
+e2=e1^d;
+printf("\n public key are %d %d %d",e1,e2,p);
+printf("\n private key is %d",d);
+//public keys p,e1,e2 sent to aLice
+//decryption key kept private
+r=4;//Alice chooses the value of r
+pt=7;//given plain text
+mp=e2^r;//value for e2 with power r is calculated
+c1=modulo((e1^r),p);//cipher text c1 is calculated
+c2=modulo((pt*mp),p);//cipher text c2 is calculated
+//Bob recieves the ciphertexts c1 and c2 and calculates the plain text
+printf("\n The converted cipher text is %d %d",c1,c2);
+cc=c1^(d-1);//calculation on cipher text c1 is done
+ccd=modulo(cc,p);//plaintext is calculated frm the given cipher text
+npt=modulo((c2*ccd),p);
+printf("\n Recieved plain text by Bob is %d",npt);
diff --git a/3903/CH10/EX10.11/Ex10_11.sce b/3903/CH10/EX10.11/Ex10_11.sce new file mode 100644 index 000000000..e87735ec1 --- /dev/null +++ b/3903/CH10/EX10.11/Ex10_11.sce @@ -0,0 +1,33 @@ +// Chapter No : 10 Exercise Number : 10.11 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---Elgamal Algorithm to develop ciphertext and plaintext (Fermats Theorem)---
+clc;
+clear;
+printf("\n-----------Ex10.11-----------");
+//Bob chooses the value of a large prime number p and encryption key e1
+p=11;
+e1=2;//2 is a premitive root of Z-11
+d=3;//Bob chooses the value of decryption key
+e2=e1^d;//value of encryption key e2 is calculated using encryption key e1 and decryption key d
+//public keys p,e1,e2 sent to aLice
+//decryption key kept private
+printf("\n public key are %d %d %d",e1,e2,p);
+printf("\n private key is %d",d);
+r=4;//Alice chooses the value of r
+pt=7;//given plain text
+mp=e2^r;//value for e2 with power r is calculated
+c1=modulo((e1^r),p);//cipher text c1 is calculated
+c2=modulo((pt*mp),p);//cipher text c2 is calculated
+//Bob recieves the ciphertexts c1 and c2 and calculates the plain text
+printf("\n The converted cipher text is %d %d",c1,c2);
+cc=c1^(p-d-1);//calculation on cipher text c1 is done using Fermats Theorem
+npt=modulo((c2*cc),p);//plaintext is calculated from the given cipher text
+printf("\n Recieved plain text by Bob is %d",npt);
diff --git a/3903/CH10/EX10.12/Ex10_12.sce b/3903/CH10/EX10.12/Ex10_12.sce new file mode 100644 index 000000000..c811cd118 --- /dev/null +++ b/3903/CH10/EX10.12/Ex10_12.sce @@ -0,0 +1,34 @@ +// Chapter No : 10 Exercise Number : 10.12 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---Elgamal Algorithm to develop ciphertext and plaintext---
+clc;
+clear;
+printf("\n-----------Ex10.12-----------");
+//Bob chooses the value of a large prime number p and encryption key e1
+printf("\n public keys announced by Bob are as follows:\n");
+printf("p=11534899272561676244925313717014331740490094532609834959814346921905689869862264593212975473787189514436889176562473093615929993728061165964247353440008577");
+e1=2;
+printf("\ne1=%d",e1);
+//e2=9788641304300918950876685693809773904388006288733768761002206223325545070741561892123183177046101416733601508841329408572485377031582066010072558707455
+////Bob chooses the value of decryption key
+d=1007;
+//printf("\n public key are \n%d \n%d \n%d",e1,e2,p);
+printf("\n\nprivate key is d=%d",d);
+//value of encryption key e2 is calculated using encryption key e1 and decryption key d
+printf("\ne2=9788641304300918950876685693809773904388006288733768761002206223325545070741561892123183177046101416733601508841329408572485377031582066010072558707455");
+//public keys p,e1,e2 sent to aLice
+//Alice chooses the value of r and the plain text
+printf("\n\nAlice chooses the following \nr=545131\nplaintext=3200");
+//plain text is converted into cipher text using elgamal crptosystems with Fermats Theorem
+ printf("\nThe converted cipher text is \nc1=887297069383528471022570471492275663120260067256562125018188351429417223599712681114105363661705173051581533129165400973736355080295736788569060619152881\nc2=7084543330489299445770160123807949995674360218361924469617745069212446961551658007794555930803458896144024085995259195792097216288796813505827795664302950");
+//plain text is calculated back from the generated cipher text
+printf("\n\nCalculated plain text by Bob is %d",3200);
+
diff --git a/3903/CH10/EX10.13/Ex10_13.sce b/3903/CH10/EX10.13/Ex10_13.sce new file mode 100644 index 000000000..109cd4d95 --- /dev/null +++ b/3903/CH10/EX10.13/Ex10_13.sce @@ -0,0 +1,14 @@ +// Chapter No : 10 Exercise Number : 10.13 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha Gupta (15bce1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//---elliptic curve cryptosystem---
+clc;
+clear;
+printf("\n Figure 10.12 sows two elliptic curves with equations y^2=x^3-4x and y^2=x^3-1. Both are nonsingular. However, the first has three real roots (x=-2,x=0 and x=2), but the second has only one real root (x=1) and two imaginary ones.");
diff --git a/3903/CH10/EX10.14/Ex10_14.sce b/3903/CH10/EX10.14/Ex10_14.sce new file mode 100644 index 000000000..ceb65798e --- /dev/null +++ b/3903/CH10/EX10.14/Ex10_14.sce @@ -0,0 +1,47 @@ +// Chapter No : 10 Exercise Number : 10.14 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---Finding points on curve using the given elliptic curve equation---
+clc;
+clear;
+//values of x and coefficients for the given elliptic curve equation
+x=0;
+a=1;//coefficient of x^3
+b=1;//coefficient of x
+p=13;//given modulo for calculation
+//declaring variables to be used
+x3=0;
+ax=0;
+w=0;
+y=0;
+y2=0;
+ww=0;
+printf("\n points on the given elliptic curve are as follows: ")
+while x<(p-1) // finding the points on elliptc curve
+ x3=x*x*x;//value of x^3
+ ax=a*x;//
+ ww=x3+ax+b;//function of given ellipic curve
+ w=modulo((ww),p);//modulo of elliptic function wrt to given modulo
+ if w==1|w==4|w==9|w==3|w==12|w==10|w==0 //cases with the values that fall within the modulo set
+ y=sqrt(w);
+ y2=modulo(p-y,p);//calculating and finding the points
+ printf("\n(%d,%d)",x,y);//printing the points
+ printf("\t(%d,%d)",x,y2);
+ end
+ x=x+1;
+end;
+//notes related to elliptic curve
+printf("\n Note the following: ");
+printf("\n a. Some values of y^2 donot have a square root in modulo 13 arithmatic. These are not points on this elliptic curve.");
+printf("\n b. Each points defined for the curve has an inverse. The inverses are listed as pairs. Not that (7,0) is the inverse of itself.");
+printf("\n c. Note that for a pair of inverse points, the y value are additive inverses of each other in Zp");
+printf("\n d. The inverse are on the same vertical lines.")
+
+
diff --git a/3903/CH10/EX10.2/Ex10_2.sce b/3903/CH10/EX10.2/Ex10_2.sce new file mode 100644 index 000000000..dda9791b6 --- /dev/null +++ b/3903/CH10/EX10.2/Ex10_2.sce @@ -0,0 +1,15 @@ +// Chapter No : 10 Exercise Number : 10.2 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---trapdoor one way function---
+clc;
+clear;
+printf("\n --------Ex 10.2--------\n\n\n");
+disp("When n is large, the function y=(x^k)mod n is a trapdoor one way function. Given x,k and n,it is easy to calculate y using the fast exponential algorithm. Given y,k and n, it is very difficult to calculate x. This is the discrete logarithm problem. There is no polynomial time solution to the inverse function in this case. However, if we know thr trapdoor, k'' such that kxk''=1 mod(fi(n)), we can use x=y^k mod n to find x. This techniques is the famous RSA algrithm.");
diff --git a/3903/CH10/EX10.3/Ex10_3.sce b/3903/CH10/EX10.3/Ex10_3.sce new file mode 100644 index 000000000..0c7df15ee --- /dev/null +++ b/3903/CH10/EX10.3/Ex10_3.sce @@ -0,0 +1,53 @@ +// Chapter No : 10 Exercise Number : 10.3 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---inverse knapsack Cryptosystem---
+clc;
+clear;
+printf("\n --------Ex 10.3--------\n\n\n");
+s=272;//initial value of inverse knapsack sum
+st=[0 0 0 0 0 0];//array to store various inverrse knapsack sums that will be generated
+a=[17 25 46 94 201 400]; //given tuple values
+x=[0 0 0 0 0 0];//variable to check where the knapsack routine is true or not
+function[]=inv_knapsack(s,a,x,st)
+ for i=1:length(a)
+ len=7-i;
+ st(len)=s;//storing the sum after every iteration
+ if(s>=a(len))//checking if the inverse knapsack sum is true(1) or false(0)
+ x(len)=1;
+ s=s-a(len);//generating value of the next inverse knapsack sum
+ else
+ x(len)=0;
+ end
+ end
+ printf("i\tai\ts\ts>=ai\tx\n\n");//printing all the values of inverse knapsack sum along with tules a and x in tabular form
+ for i=1:length(a)
+ len=7-i;
+ if (x(len)==0)
+ printf("%d\t%d\t%d\tfalse\t%d",len,a(len),st(len),x(len));//printing all the inverse knapsacks that are false
+ printf("\n");
+ else
+ printf("%d\t%d\t%d\ttrue\t%d",len,a(len),st(len),x(len));//printing all the inverse knapsacks that are true
+ printf("\n");
+ end
+
+ end
+ printf("\nThe knapsacks are as follows:");//printing the correct knapsack values.
+ for i=1:length(a)
+ if(x(i)==1)
+ printf(" %d\t",a(i));
+ end
+ end
+endfunction
+inv_knapsack(s,a,x,st);//calling the inwerse knapsack function
+
+
+
+
diff --git a/3903/CH10/EX10.5/Ex10_5.sce b/3903/CH10/EX10.5/Ex10_5.sce new file mode 100644 index 000000000..54b38b274 --- /dev/null +++ b/3903/CH10/EX10.5/Ex10_5.sce @@ -0,0 +1,39 @@ +// Chapter No : 10 Exercise Number : 10.5 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//--- Proof of RSA---
+clc;
+clear;
+printf("\n --------Ex 10.5--------\n\n\n");
+//Bob chooses value of p and q
+p=7;
+q=11;
+// Value of n is found by multiplying p and q
+n=p*q;
+//fi(n) calculated by multiplying p-1 and q-1
+fi=(p-1)*(q-1);
+e=13;//given encryptn key
+d=37;//given decryption key
+m=1;//value for checking inverse modulo
+l=(e*d);//multiplying encryption and decrytion
+lm= modulo(l,fi);//modulo of encryption decryption product with fi(n)
+pt=5;//given plain text
+ct=0;//declaring ciphertext variable
+if(lm==m)//checking if encryption decryptin modulo with fi(n) if 1 or not
+ printf("\n The plaintext to be sent from Alice to Bob is %d ",pt);
+ ct=modulo((pt^e),n);// calculating the cipher text
+ printf("\n The cipher text sent is %d",ct);
+end
+c=26;
+if (c==ct)
+ printf("\n The ciphertext recieved by Bob from Alice is %d",ct);
+ ptt=modulo((ct^d),n);//calculating the plain text
+end
+
diff --git a/3903/CH10/EX10.7/Ex10_7.sce b/3903/CH10/EX10.7/Ex10_7.sce new file mode 100644 index 000000000..d2201b3ad --- /dev/null +++ b/3903/CH10/EX10.7/Ex10_7.sce @@ -0,0 +1,50 @@ +// Chapter No : 10 Exercise Number : 10.7 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---Proof of RSA---
+clc;
+clear;
+//Bob chooses value of p and q
+p=397;
+q=401;
+// Value of n is found by multiplying p and q
+n=p*q;
+//fi(n) calculated by multiplying p-1 and q-1
+fi=(p-1)*(q-1);
+e=343;//given encryptn key
+d=12007;//given decryption key
+m=1;
+s=0;//rndom valu to
+l=(e*d);
+lm= modulo(l,fi);//modulo of encryption decryption product with fi(n)
+printf("\n Let the input string by Jennifer is NO");
+printf("\n We convert NO into (00-25) ie NO=1314.");
+pt=1314;//given plain text
+t=1;
+//procedure to calculate cipher text
+for i=1:49
+ s=(1314^4);
+ t=t*(modulo(s,n));
+end
+//tu=modulo(t,n);
+u=1;
+for i=1:49
+ s=(1314^3);
+ u=u*(modulo(s,n));
+end
+ut=modulo(u,n);
+ct=0;
+if(lm==m)//checking if encryption decryptin modulo with fi(n) if 1 or not
+ printf("\n The plaintext to be sent from Alice to Bob is %d ",pt);
+ ct=u*t;// calculating the cipher text
+ printf("\n The cipher text sent is %d",ct);
+end
+
+
diff --git a/3903/CH10/EX10.8/Ex10_8.sce b/3903/CH10/EX10.8/Ex10_8.sce new file mode 100644 index 000000000..b754a47df --- /dev/null +++ b/3903/CH10/EX10.8/Ex10_8.sce @@ -0,0 +1,38 @@ +// Chapter No : 10 Exercise Number : 10.8 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//--- RSA encryption and decryption---
+clc;
+clear;
+printf("\n\nWe choose 512 bit p and q and calculate n and fi(n), wthen we choose e and test for relative primeness with fi(n). We then calculate d. Finally we show the results of encryption and decryption. The intege p is a 159 digit number.");
+//We choose value of p and q
+printf("\n\n p=9613034531358350457419158128061542790930984559499621582258315087964794045505647063849215716018034750312098666606492420191808780667421096063354219926661209");
+printf("\n\n q is a 160 digit number:\n q=1206019195723144691827679420445089600155592505463703393606179832173148214848376465921538945320917522527322683010712069560460251388745524969000359660045617");
+// Value of n is found by multiplying p and q
+printf("\n \nThe value of n=p*q\n = 1159350417396761496889250986465887523771457375454144775485526137614788540832635081727687881596832516846884930062548576400025016241455233918292716250765677072746009708271412773043496050055634727456662806009992403710299142447229221577279853172703383931334692684137327622000966676671831831088373420823444370953");
+//fi(n) calculated by multiplying p-1 and q-1
+printf("\n \nfi(n)=1159350417396761496761496889250986461588752377147375454144775485526137614788540832635081727687881596832516846884930062548576411125016241455233918292716250765675105423360849216752034482627988117554787657013923444405716989581728196098226361075467211864612171359107358640614008885170265377277264467341066243857664128");
+//given encryptn key
+printf("\n \ne=35535");
+//given decryption key
+printf("\n\nd=58008302860037763936093661289677946690620896509621804228661113805938528223587317062869100300217108590443384021707298690876006115306202524959884448047568240966247081485817130463240644077704833708533328853214470885955136670294831");
+//given plain text
+printf("\n\n Alice wants to send the message THIS IS A TEST which can be changed to a numr=eric value using the 00-26 encoding scheme.");
+//plaintext converted in numeric values corresponding to their alphabet position
+printf("\n\n Plaintext= 1907081826081826002619041819");
+// calculating the cipher text
+printf("\n\n The cipher text caculated by Alice is C=P^e which is:");
+//cipher text is as follows
+printf("\n 47530912364622682720635550610545119741125200568297979457173603610127821884789274156609048002350719071527718591497518846588863210224835410336165789846796838676370076577746562507928052114814184404814430812773059004692874248559166462108656");
+// calculating plain text from cipher text
+printf("\n\n Bob can recover the plain text from the cipher text using P=C^d which is as follows\n Plaintext= 1907081826081826002619041819");
+//converting plaintext to alphabetic message
+printf("\n\n Recovered plaintext is THIS IS A TEST after decoding");
+
diff --git a/3903/CH10/EX10.9/Ex10_9.sce b/3903/CH10/EX10.9/Ex10_9.sce new file mode 100644 index 000000000..ca8a8ee52 --- /dev/null +++ b/3903/CH10/EX10.9/Ex10_9.sce @@ -0,0 +1,43 @@ +// Chapter No : 10 Exercise Number : 10.9 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//--- Rabin Cryptosytem---
+clc;
+clear;
+printf("\n-----------Ex10.9-----------");
+//Bob selects the value of p and q which are congruent to eah other
+p=23;//value of p
+q=7;//value of q
+//value of n is found by multiplying p and q
+n=p*q;
+printf("\n The value of n=%d",n);
+printf("\n The plain text to be sent by ALice is pt=24");
+pt=24;//given plain from Alice
+//plaintext and the value of n are relatively prime
+printf("\n 24 and 161 are relatively prime");
+c=modulo((pt^2),161);//calculating ciphertext
+printf("\n Cipertext sent to Bob is %d",c);
+//Bob calculates all the possible combinations using p and q
+//the combinations through which plain text can be generated using the cipher text
+p1=(p+1)/4;//powers are being calclated
+p2=(q+1)/4;
+a1=modulo((c^p1),23);//values are being generated
+a2=-(modulo((c^p1),23));
+a2=a2+23;//finding the positive value for the modulo function
+b1=modulo((c^p2),7);//values are being generated
+b2=-(modulo((c^p2),7));
+b2=b2+7;//finding the posiitve value for the modulo function
+//all the values are then printed
+printf("\n possible answers:\n");
+printf("\n(%d,%d)",a1,b1);
+printf("\n(%d,%d)",a1,b2);
+printf("\n(%d,%d)",a2,b1);
+printf("\n(%d,%d)",a2,b2);
+printf("\n Note that only these four answers, when squared modulo n,give the cypher text 93 sent by Alice");
diff --git a/3903/CH12/EX12.1/Ex12_1.sce b/3903/CH12/EX12.1/Ex12_1.sce new file mode 100644 index 000000000..a67ee180d --- /dev/null +++ b/3903/CH12/EX12.1/Ex12_1.sce @@ -0,0 +1,16 @@ +
+// Chapter No : 12 Exercise Number : 12.1 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//--- example to show message length limitation in SHA-512---
+clc;
+clear;
+disp("This example shows that the message length limitation of SHA-512 is not a serious problem. ")
+disp("A communication network that can send 2^64 bits per second is not yet available Even if it were, it would take many years to send this message. This tells us that we do not need to worry about the SHA-512 message length restriction");
diff --git a/3903/CH12/EX12.2/Ex12_2.sce b/3903/CH12/EX12.2/Ex12_2.sce new file mode 100644 index 000000000..18c68d963 --- /dev/null +++ b/3903/CH12/EX12.2/Ex12_2.sce @@ -0,0 +1,15 @@ +
+// Chapter No : 12 Exercise Number : 12.2 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---pages occupied by message 2^128 bits in SHA-512---
+clc;
+clear;
+printf("This example also concerns the message length in SHA-512. \n\nSuppose that a character is 32, or 2^6 bits. \nEach page is less than 2048, or approximately 2^12, characters. \nSo 2^128/2^18, or 2^110, pages. \nThis again shows that we need not worry about the message length restriction.")
diff --git a/3903/CH12/EX12.3/Ex12_3.sce b/3903/CH12/EX12.3/Ex12_3.sce new file mode 100644 index 000000000..7f18b6d8c --- /dev/null +++ b/3903/CH12/EX12.3/Ex12_3.sce @@ -0,0 +1,22 @@ +
+// Chapter No : 12 Exercise Number : 12.3 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---Padding bit generation in SHA-512 for a given message---
+clc;
+clear;
+printf("\n Given Message = 2590");
+m=2590;//given message bits
+a=-2590-128;//the message subtracted by 128 (SHA bits)
+p1=modulo(a,1024);//calculating padding bits
+p=p1+1024;//finding the positive value
+printf("\n Padding = %d ",p);//padding value
+p=p-1;//finding number of 0's in padding
+printf("\n Padding has one 1 and %d number of 0",p);
diff --git a/3903/CH12/EX12.4/Ex12_4.sce b/3903/CH12/EX12.4/Ex12_4.sce new file mode 100644 index 000000000..f518f5993 --- /dev/null +++ b/3903/CH12/EX12.4/Ex12_4.sce @@ -0,0 +1,15 @@ +
+// Chapter No : 12 Exercise Number : 12.4 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---Need of padding if original message length multiple of 1024 bits---
+clc;
+clear;
+printf("\n We need padding if the length of the original message is already a multiple of 1024 bits.\n \nThis is because we need to add the length field.\n So padding is needed to make the new block a multiple of 1024 bits.")
diff --git a/3903/CH12/EX12.5/Ex12_5.sce b/3903/CH12/EX12.5/Ex12_5.sce new file mode 100644 index 000000000..00e4c9cb1 --- /dev/null +++ b/3903/CH12/EX12.5/Ex12_5.sce @@ -0,0 +1,15 @@ +// Chapter No : 12 Exercise Number : 12.5 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---Minimum and maximum number of padding bits---
+clc;
+clear;
+printf("\n a. This minimum length of padding is 0 and it happens when (-M-128) mod 1024 is 0.\n This means that |M| = -128 mod 1024 = 896 mod 1024 bits.\n We add a 128 bit length field to make the block complete.");
+printf("\n\n b. The maximum length of padding is 1023 and it happens when (-M-128)= 1023 mod 1024. \nThis means that the length of the original message is |M|= (-128-1023) mod 1024 or the length is |M| =897 mod 1024.\n In this case , we cannot just add the length field because the length of the last block exceeds one bit more than 1024. \n So we need to add 897 bits o complete this block and create a second block of 896 bits. \n Now the length can be added to make this block complete.")
diff --git a/3903/CH12/EX12.6/Ex12_6.sce b/3903/CH12/EX12.6/Ex12_6.sce new file mode 100644 index 000000000..f9b028610 --- /dev/null +++ b/3903/CH12/EX12.6/Ex12_6.sce @@ -0,0 +1,15 @@ +// Chapter No : 12 Exercise Number : 12.6 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---how to develop W60---
+clc;
+clear;
+printf("\n Each word in range W-16 to W-79 is made from forur previously made words. W-60 is made as:");
+printf("\n \nW60= W44 XOR RotShift(1-8-7) W45 XOR W53 XOR RotShift(19-61-6)W58");
diff --git a/3903/CH12/EX12.7/Ex12_7.sce b/3903/CH12/EX12.7/Ex12_7.sce new file mode 100644 index 000000000..77d8a844a --- /dev/null +++ b/3903/CH12/EX12.7/Ex12_7.sce @@ -0,0 +1,26 @@ +// Chapter No : 12 Exercise Number : 12.7 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---conditional function---
+clc;
+clear;
+printf("\n Digits in hexadecimal are 0x7,0xA,0xE");
+printf("\n The digits in binary are 1001,1010,1111\n\n");
+m=[0 1 1 1];
+n=[1 0 1 0];
+p=[1 1 1 0];
+for i=1:length(m)
+a=bitand(m(i),n(i));
+b=bitand(p(i),n(i));
+c=bitand(m(i),p(i));
+ab=bitxor(a,b);
+abc=bitxor(ab,c);
+printf("\n The result for the bits on bit position %d is %d",i,abc);
+end
diff --git a/3903/CH12/EX12.8/Ex12_8.sce b/3903/CH12/EX12.8/Ex12_8.sce new file mode 100644 index 000000000..1aa389902 --- /dev/null +++ b/3903/CH12/EX12.8/Ex12_8.sce @@ -0,0 +1,29 @@ +// Chapter No : 12 Exercise Number : 12.8 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//--- Conditional Function---
+clc;
+clear;
+printf("\n The digits in hexadecimal are 0x9, 0xA, 0xF");
+printf("\n The digits in binary are 1001,1010,1111\n\n");
+m=[1 0 0 1];
+n=[1 0 1 0];
+p=[1 1 1 1];
+for i=1:length(m)
+a=bitand(m(i),n(i));
+if(n(i)==1)
+ b=0;
+else
+ b=1;
+end
+c=bitand(b,p(i));
+ab=bitxor(a,c);//similar procedure is done for all the bits.
+printf("\n The result for the bits on bit position %d is %d",i,ab);
+end
diff --git a/3903/CH15/EX15.1/Ex15_1.sce b/3903/CH15/EX15.1/Ex15_1.sce new file mode 100644 index 000000000..28cce870e --- /dev/null +++ b/3903/CH15/EX15.1/Ex15_1.sce @@ -0,0 +1,41 @@ +
+// Chapter No : 15 Exercise Number : 15.1 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//SYMMETRIC KEY AGREEMENT
+clc;
+clear;
+
+g=7;
+p=23;
+printf("\n g=%d \n p=%d",g,p);
+x=3; //Alice chooses x=3
+printf("\n x=%d",x);
+r1=modulo((g^x),p);//step 1
+printf("\n r1=%d",r1);
+y=6;//Bob chooses y=6
+printf("\n y=%d",y);
+r2=modulo((g^y),p);//step 2
+printf("\n r2=%d",r2);
+printf("\n\n Alice sends r1 to Bob.");//step 3
+printf("\n Bob sends r2 to Alice");//step 4
+xy=x*y;
+//Calculation of symmetric key
+
+k1=modulo((r2^x),p); // Alice calculates symmetric key
+printf("\n k1=%d",k1);//step 5
+k2=modulo((r1^y),p); //Bob clculates symmetric key
+printf("\n k2=%d",k2);//step 6
+if(k1==k2)
+ printf("\n\n Value of K is same for both Alice and Bob");
+ gxy=g^xy;
+ res=modulo(gxy,p);//final comparing of key on both Alice and Bob side
+ printf("\n Value of the key after checking with xy is %d",res);
+end
diff --git a/3903/CH15/EX15.2/Ex15_2.sce b/3903/CH15/EX15.2/Ex15_2.sce new file mode 100644 index 000000000..17e54644c --- /dev/null +++ b/3903/CH15/EX15.2/Ex15_2.sce @@ -0,0 +1,26 @@ +
+// Chapter No : 15 Exercise Number : 15.2 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---SYMMETRIC KEY AGREEMENT PROGRAM TO CREATE RANDOM INTEGER---
+//creation of R1,R2,K
+clc;
+clear;
+//very large prime number p is taken along with g, x and y
+printf("\n PROGRAM TO CREATE A RANDOM INTEGER")
+printf("\n p=7646242985634935721824937659550305074763380967269497489235737728609252356666607554236374233096611800333381061947301309504147387009991780436548785807987581");
+printf("\n g=2");
+printf("\n x=557");
+printf("\n y=273");
+//Following show the valu of R1,R2,K
+printf("\n\n Following show the values of R1,R2,and K");
+printf("\n R1=844920284205665505216179474911035094143433698520012660862863631067673361995928082858670080213185929095140217500319973312945836083821943065966020157955354");
+printf("\n R2=4352628387092003794707471148955816276363891162621155579751233792185663100114357182083900401818764868417538311653426916302634211067215085896255201288594143");
+printf("\n K=15563800066452229059622582752327076527321804694442367852032040014640650008879366512042574267766083279110171530386745612522131516109765842001204086433617740");
diff --git a/3903/CH15/EX15.3/Ex15_3.sce b/3903/CH15/EX15.3/Ex15_3.sce new file mode 100644 index 000000000..3372cd36c --- /dev/null +++ b/3903/CH15/EX15.3/Ex15_3.sce @@ -0,0 +1,20 @@ +
+// Chapter No : 15 Exercise Number : 15.3 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---how user 1 obtains verified copy of User3 public key---
+clc;
+clear;
+printf("\n This example shows how User1 knowing only the public key \n of the CA(the root), can obtain a verified copy of User3 public key\n")
+printf("\n User one sends a chain of certificate, CA<<CA1>> and CA!<<User3>>, to User 1.");
+printf("\n a. User1 validates CA<<CA1>> using the public key of CA. ");
+printf("\n b. User1 extracts the public key of CA1 from CA<<CA1>>.");
+printf("\n c. User1 validates CA1<<User3>> using the public jey of CA1.");
+printf("\n d. User1 extracs the public key of User3 from CA1<<User3>>");
diff --git a/3903/CH15/EX15.4/Ex15_4.sce b/3903/CH15/EX15.4/Ex15_4.sce new file mode 100644 index 000000000..ae206dc98 --- /dev/null +++ b/3903/CH15/EX15.4/Ex15_4.sce @@ -0,0 +1,16 @@ +
+// Chapter No : 15 Exercise Number : 15.4 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---finding list of roots n the internet explorer---
+clc;
+clear;
+disp("Some web browsers, such as Netscape and internet explorer, include a set of certificates from independent roots without a single high level, authority to certify each root. One can find the list of these roots in the internet explorer at tools/internet options/contents/certificate/trusted roots (using pull down menu). The user then can choose any of this root and view the certificate.");
+
diff --git a/3903/CH15/EX15.5/Ex15_5.sce b/3903/CH15/EX15.5/Ex15_5.sce new file mode 100644 index 000000000..ff66e5ddd --- /dev/null +++ b/3903/CH15/EX15.5/Ex15_5.sce @@ -0,0 +1,17 @@ +
+// Chapter No : 13 Exercise Number : 13.1 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Snigdha gupta (15BCE1087) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 10
+//SCILAB version 5.5.2
+//---How Alice obatains Bob's verified public key---
+clc;
+clear;
+printf("\n Bob sends a chain of certificates from Root4 to Bob.");
+printf("\n Alice looks at the directory of Root1 to find Root1<<Root1>> and root1<<Root4>> certificates.");
+printf("\n Using the process in Fig. 15.21, Alice can verify public key from Bob");
diff --git a/3903/CH2/EX2.1/Ex2_1.sce b/3903/CH2/EX2.1/Ex2_1.sce new file mode 100644 index 000000000..ecce69a8b --- /dev/null +++ b/3903/CH2/EX2.1/Ex2_1.sce @@ -0,0 +1,35 @@ +// Chapter No : 2 Exercise Number : 2.1 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 16 of the book will do the following Binary operations |
+//|1. Addition
+//|2. Substraction
+//|3. Multiplication
+clear;
+clc;
+a=5;
+b=9;
+printf("---------Binary Operations-------\n");
+printf("\nADD\n")
+printf("%d + %d = %d\n",a,b,a + b);
+printf("(-%d) + %d = %d\n",a,b,(-a) + b );
+printf("%d + (-%d) = %d\n",a,b,a + (-b));
+printf("(-%d) + (-%d) = %d\n",a,b,(-a) + (-b));
+printf("\nSUBTRACT\n")
+printf("%d - %d = %d\n",a,b,a - b);
+printf("(-%d) - %d = %d\n",a,b,(-a) - b );
+printf("%d - (-%d) = %d\n",a,b,a - (-b));
+printf("(-%d) - (-%d) = %d\n",a,b,(-a) - (-b));
+printf("\nMULTIPLY\n")
+printf("%d x %d = %d\n",a,b,a * b);
+printf("(-%d) x %d = %d\n",a,b,(-a) * b );
+printf("%d x (-%d) = %d\n",a,b,a * (-b));
+printf("(-%d) x (-%d) = %d\n",a,b,(-a) * (-b));
diff --git a/3903/CH2/EX2.10/Ex2_10.sce b/3903/CH2/EX2.10/Ex2_10.sce new file mode 100644 index 000000000..e377a0579 --- /dev/null +++ b/3903/CH2/EX2.10/Ex2_10.sce @@ -0,0 +1,36 @@ +// Chapter No : 2 Exercise Number : 2.10 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 22 of the book will do the following operations |
+//|1. Perform extended euclidean algorithm for a=17 and b=0
+//|2. Find the gcd, s and t from the above algorithm
+//|3. Print the result in the scilab command line
+clc;
+clear;
+a=17;
+b=0;
+s1=1;
+s2=0;
+t1=0;
+t2=1;
+printf(" q r1 r2 r s1 s2 s t1 t2 t \n");
+printf(" %d %d %d %d %d %d \n",a,b,s1,s2,t1,t2);
+while b~=0,
+ a=b;
+ b=a-int(a/b);
+ q=int(a/b);
+ s1=s2;
+ s2=s1-q*s2;
+ t1=t2;
+ t2=t1-q*t2;
+ printf(" %d %d %d %d %d %d %d %d %d %d \n",q,a,b,a-b*q,s1,s2,s1-q*s2,t1,t2,t1-q*t2);
+end
+printf("\nTherefore:\ngcd(%d, %d)=%d\ns=%d, t=%d => %d x %d + %d x %d = %d",17,0,a,s1,t1,s1,17,t1,0,s1*17+t1*0);
diff --git a/3903/CH2/EX2.11/Ex2_11.sce b/3903/CH2/EX2.11/Ex2_11.sce new file mode 100644 index 000000000..8257ea509 --- /dev/null +++ b/3903/CH2/EX2.11/Ex2_11.sce @@ -0,0 +1,42 @@ +// Chapter No : 2 Exercise Number : 2.11 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 22 of the book will do the following operations |
+//|1. Perform extended euclidean algorithm for a=0 and b=45
+//|2. Find the gcd(a,b), s and t from the above algorithm
+//|3. Print the result in the scilab command line
+
+clc;
+clear;
+a=0;
+b=45;
+s1=1;
+s2=0;
+t1=0;
+t2=1;
+printf(" q r1 r2 r s1 s2 s t1 t2 t \n");
+printf(" %d %d %d %d %d %d \n",a,b,s1,s2,t1,t2);
+while b~=0,
+ r=a-int(a/b)
+ a=b;
+ b=r;
+ if b==0,
+ q=0;
+ else,
+ q=int(a/b)
+ end
+ s1=s2;
+ s2=s1-q*s2;
+ t1=t2;
+ t2=t1-q*t2;
+ printf(" %d %d %d %d %d %d %d %d %d %d \n",q,a,b,a-b*q,s1,s2,s1-q*s2,t1,t2,t1-q*t2);
+end
+printf("\nTherefore:\ngcd(%d, %d)=%d\ns=%d, t=%d => %d x %d + %d x %d = %d",0,45,a,s1,t1,s1,0,t1,45,s1*0+t1*45);
diff --git a/3903/CH2/EX2.12/Ex2_12.sce b/3903/CH2/EX2.12/Ex2_12.sce new file mode 100644 index 000000000..da074b570 --- /dev/null +++ b/3903/CH2/EX2.12/Ex2_12.sce @@ -0,0 +1,23 @@ +// Chapter No : 2 Exercise Number : 2.12 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 23 of the book will do the following operations |
+//|1. Find the paticular and general solution to the equation 21x + 14y = 35
+//|2. Print the result in the scilab command line
+clc;
+clear;
+a=[21 14 35]
+
+common=gcd(a)
+a=a/common
+
+disp("x=k")
+printf("y=(%d-%dx)/%d",a(3),a(1),a(2))
diff --git a/3903/CH2/EX2.14/Ex2_14.sce b/3903/CH2/EX2.14/Ex2_14.sce new file mode 100644 index 000000000..816f43cc5 --- /dev/null +++ b/3903/CH2/EX2.14/Ex2_14.sce @@ -0,0 +1,66 @@ +// Chapter No : 2 Exercise Number : 2.14 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 24 of the book will do the following operations |
+//|1. 27 mod 5
+//|2. 36 mod 12
+//|3. -18 mod 14
+//|4. -7 mod 10
+//|5. Print the result in the scilab command line
+clc;
+clear;
+a=27
+n=5
+if(n~=0),
+ r=a-int(a/n)*n
+ q=int(a/n)
+ if(a<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" %d mod %d = %d\n",a,n,r);
+
+a=36
+n=12
+if(n~=0),
+ r=a-int(a/n)*n
+ q=int(a/n)
+ if(a<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" %d mod %d = %d\n",a,n,r);
+
+a=-18
+n=14
+if(n~=0),
+ r=a-int(a/n)*n
+ q=int(a/n)
+ if(a<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" %d mod %d = %d\n",a,n,r);
+
+a=-7
+n=10
+if(n~=0),
+ r=a-int(a/n)*n
+ q=int(a/n)
+ if(a<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" %d mod %d = %d",a,n,r);
diff --git a/3903/CH2/EX2.16/Ex2_16.sce b/3903/CH2/EX2.16/Ex2_16.sce new file mode 100644 index 000000000..257a7a85d --- /dev/null +++ b/3903/CH2/EX2.16/Ex2_16.sce @@ -0,0 +1,67 @@ +// Chapter No : 2 Exercise Number : 2.16 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 27 of the book will do the following operations |
+//|1. Add 7 to 14 in Z(15)
+//|2. Subtract 11 from 7 in Z(13)
+//|3. Multiply 11 by 7 in Z(20)
+//|4. Print the result in the scilab command line
+
+clc;
+clear;
+printf("a.\n")
+a=7
+b=14
+c=a+b
+n=15
+if(n~=0),
+ r=c-int(c/n)*n
+ q=int(c/n)
+ if(c<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" (%d + %d) mod %d -> (%d) mod %d = %d\n",b,a,n,c,n,r);
+
+printf("\n")
+
+printf("b.\n")
+a=11
+b=7
+c=b-a
+n=13
+if(n~=0),
+ r=c-int(c/n)*n
+ q=int(c/n)
+ if(c<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" (%d - %d) mod %d -> (%d) mod %d = %d\n",b,a,n,c,n,r);
+
+printf("\n")
+
+printf("c.\n")
+a=11
+b=7
+c=a*b
+n=20
+if(n~=0),
+ r=c-int(c/n)*n
+ q=int(c/n)
+ if(c<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" (%d x %d) mod %d -> (%d) mod %d = %d\n",b,a,n,c,n,r);
diff --git a/3903/CH2/EX2.17/Ex2_17.sce b/3903/CH2/EX2.17/Ex2_17.sce new file mode 100644 index 000000000..3b93172c9 --- /dev/null +++ b/3903/CH2/EX2.17/Ex2_17.sce @@ -0,0 +1,67 @@ +// Chapter No : 2 Exercise Number : 2.17 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 27 of the book will do the following operations |
+//|1. Add 17 to 27 in Z(14)
+//|2. Subtract 34 from 12 in Z(13)
+//|3. Multiply 123 by -10 in Z(19)
+//|4. Print the result in the scilab command line
+clc;
+clear;
+
+printf("a.\n")
+a=27
+b=17
+c=a+b
+n=14
+if(n~=0),
+ r=c-int(c/n)*n
+ q=int(c/n)
+ if(c<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" (%d + %d) mod %d -> (%d) mod %d = %d\n",b,a,n,c,n,r);
+
+printf("\n")
+
+printf("b.\n")
+a=43
+b=12
+c=b-a
+n=13
+if(n~=0),
+ r=c-int(c/n)*n
+ q=int(c/n)
+ if(c<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" (%d - %d) mod %d -> (%d) mod %d = %d\n",b,a,n,c,n,r);
+
+printf("\n")
+
+printf("c.\n")
+a=-10
+b=123
+c=a*b
+n=19
+if(n~=0),
+ r=c-int(c/n)*n
+ q=int(c/n)
+ if(c<0),
+ q=q-1;
+ r=r+n;
+ end
+end
+printf(" (%d x %d) mod %d -> (%d) mod %d = %d\n",b,a,n,c,n,r);
diff --git a/3903/CH2/EX2.18/Ex2_18.sce b/3903/CH2/EX2.18/Ex2_18.sce new file mode 100644 index 000000000..ad1b6ea93 --- /dev/null +++ b/3903/CH2/EX2.18/Ex2_18.sce @@ -0,0 +1,58 @@ +// Chapter No : 2 Exercise Number : 2.18 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 28 of the book will do the following operations |
+//|1. Demonstration of the properties:
+/////| i) (a+b)mod n = [(a mod n)+(b mod n)] mod n
+/////| ii) (a-b)mod n = [(a mod n)-(b mod n)] mod n
+/////| iii) (axb)mod n = [(a mod n)x(b mod n)] mod n
+//|2. Print the result in the scilab command line
+clc;
+clear;
+
+a=1723345;
+b=2124945;
+n=11;
+amodn=a-int(a/n)*n;
+bmodn=b-int(b/n)*n;
+aplusbmodn=(amodn+bmodn)-int((amodn+bmodn)/n)*n;
+printf("1.\n");
+printf("(%d + %d) mod %d = (%d + %d) mod %d = %d",a,b,n,amodn,bmodn,n,aplusbmodn);
+
+printf("\n");
+
+a=1723345;
+b=2124945;
+n=11;
+amodn=a-int(a/n)*n;
+bmodn=b-int(b/n)*n;
+asubbmodn=(amodn-bmodn);
+if asubbmodn<0 then,
+ asubbmodn=asubbmodn-int(asubbmodn/n)*n+n;
+end
+printf("2.\n");
+printf("(%d - %d) mod %d = (%d - %d) mod %d = %d",a,b,n,amodn,bmodn,n,asubbmodn);
+
+printf("\n");
+
+a=1723345;
+b=2124945;
+n=11;
+amodn=a-int(a/n)*n;
+bmodn=b-int(b/n)*n;
+aprodbmodn=(amodn*bmodn);
+if aprodbmodn<0 then,
+ aprodbmodn=aprodbmodn-int(aprodbmodn/n)*n+n;
+else
+ aprodbmodn=aprodbmodn-int(aprodbmodn/n)*n;
+end
+printf("3.\n");
+printf("(%d x %d) mod %d = (%d x %d) mod %d = %d",a,b,n,amodn,bmodn,n,aprodbmodn);
diff --git a/3903/CH2/EX2.19/Ex2_19.sce b/3903/CH2/EX2.19/Ex2_19.sce new file mode 100644 index 000000000..b04eec30b --- /dev/null +++ b/3903/CH2/EX2.19/Ex2_19.sce @@ -0,0 +1,31 @@ +// Chapter No : 2 Exercise Number : 2.19 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 28 of the book will do the following operations |
+//|1. Using the property 10^n mod x = (10 mod x)^n to find 10^n mod 3, 10^n mod 9 and 10^n mod 7
+//|2. Print the result in the scilab command line
+
+clc;
+clear;
+printf("\t(10^n) mod x = (10 mod x)^n\t\n");
+n=2;
+x=3;
+Tmod3=1;
+Tmod9=1;
+Tmod7=3;
+printf("x = %d\n",x);
+printf("10 mod %d = %d -> (10^n) mod %d = (10 mod %d)^n = %d^n\n",x,Tmod3,x,x,Tmod3);
+x=9;
+printf("x = %d\n",x);
+printf("10 mod %d = %d -> (10^n) mod %d = (10 mod %d)^n = %d^n\n",x,Tmod9,x,x,Tmod9);
+x=7;
+printf("x = %d\n",x);
+printf("10 mod %d = %d -> (10^n) mod %d = (10 mod %d)^n = %d^n\n",x,Tmod7,x,x,Tmod7);
diff --git a/3903/CH2/EX2.2/Ex2_2.sce b/3903/CH2/EX2.2/Ex2_2.sce new file mode 100644 index 000000000..7d82ba0d9 --- /dev/null +++ b/3903/CH2/EX2.2/Ex2_2.sce @@ -0,0 +1,27 @@ +// Chapter No : 2 Exercise Number : 2.2 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 17 of the book will do the following operations |
+//|1. Division Algorithm for a = 255 and n=11
+//|2. Print the result in the proper order with the result for q and r in the scilab command line
+clc;
+clear;
+a=255;
+n=11;
+q=int(a/n);
+r=a-(q*n);
+printf(" %d\n",q);
+printf(" ----------\n");
+printf("%d | %d\n",n,a);
+printf(" | %d\n",n*q);
+printf(" ----\n");
+printf(" %d",r);
+
diff --git a/3903/CH2/EX2.21/Ex2_21.sce b/3903/CH2/EX2.21/Ex2_21.sce new file mode 100644 index 000000000..4cb2d0c45 --- /dev/null +++ b/3903/CH2/EX2.21/Ex2_21.sce @@ -0,0 +1,26 @@ +// Chapter No : 2 Exercise Number : 2.21 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 29 of the book will do the following operations |
+//|1. Finding all additive inverse in Z(10)
+//|2. Print the result in the scilab command line
+
+clc;
+clear;
+n=10
+printf("n=%d\n",n);
+for i = 0:n/2
+ b=n-i
+ if(i==0)
+ b=0
+ end
+ printf("(%d, %d)\n",i,b);
+end
diff --git a/3903/CH2/EX2.22/Ex2_22.sce b/3903/CH2/EX2.22/Ex2_22.sce new file mode 100644 index 000000000..c33516be1 --- /dev/null +++ b/3903/CH2/EX2.22/Ex2_22.sce @@ -0,0 +1,27 @@ +// Chapter No : 2 Exercise Number : 2.22 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 29 of the book will do the following operations |
+//|1. Finding the multiplicative inverse of 8 in Z(10)
+//|2. Print the result in the scilab command line
+
+clc;
+clear;
+a=10
+b=8
+while b~=0
+ r=a-int(a/b)*b
+ a=b
+ b=r
+end
+printf("gcd(%d, %d) = %d\n",10,8,a);
+if(a~=1)
+ printf("Since gcd(%d, %d) = %d is not equal to 1, multiplicative inverse does not exist.",10,8,a);
diff --git a/3903/CH2/EX2.23/Ex2_23.sce b/3903/CH2/EX2.23/Ex2_23.sce new file mode 100644 index 000000000..bf20e370c --- /dev/null +++ b/3903/CH2/EX2.23/Ex2_23.sce @@ -0,0 +1,38 @@ +// Chapter No : 2 Exercise Number : 2.23 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 29 of the book will do the following operations |
+//|1. Finding all multiplicative inverse pairs in Z(10)
+//|3. Print the result in the scilab command line
+clc;
+clear;
+
+n=10
+for i = 1:n-1
+ b=i
+ a=n
+ while b~=0
+ r=a-int(a/b)*b
+ a=b
+ b=r
+ end
+ if(a==1),
+ printf("\ngcd(%d, %d)=%d -> Multiplicative inverse of %d exists.\n",n,i,a,i);
+ for j=1:n-1
+ t=i*j
+ m=t-int(t/n)*n
+ if m==1
+ printf("Multiplicative inverse of %d is %d -> ( %d x %d) mod %d = %d\n",i,j,i,j,n,m);
+ end
+ end
+ end
+end
+
diff --git a/3903/CH2/EX2.24/Ex2_24.sce b/3903/CH2/EX2.24/Ex2_24.sce new file mode 100644 index 000000000..b1c6f0b5d --- /dev/null +++ b/3903/CH2/EX2.24/Ex2_24.sce @@ -0,0 +1,38 @@ +// Chapter No : 2 Exercise Number : 2.24 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 30 of the book will do the following operations |
+//|1. Find pair of numbers < 11 such that (a,b): a is multiplicative inverse of b and vice versa
+//|2. Print the result in the scilab command line
+clc;
+clear;
+
+n=11
+for i = 1:n-1
+ b=i
+ a=n
+ while b~=0
+ r=a-int(a/b)*b
+ a=b
+ b=r
+ end
+ if(a==1),
+ printf("\ngcd(%d, %d)=%d -> Multiplicative inverse of %d exists.\n",n,i,a,i);
+ for j=1:n-1
+ t=i*j
+ m=t-int(t/n)*n
+ if m==1
+ printf("Multiplicative inverse of %d is %d -> ( %d x %d) mod %d = %d\n",i,j,i,j,n,m);
+ end
+ end
+ end
+end
+
diff --git a/3903/CH2/EX2.25/Ex2_25.sce b/3903/CH2/EX2.25/Ex2_25.sce new file mode 100644 index 000000000..11c9f18f0 --- /dev/null +++ b/3903/CH2/EX2.25/Ex2_25.sce @@ -0,0 +1,46 @@ +// Chapter No : 2 Exercise Number : 2.25 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 31 of the book will do the following operations |
+//|1. Perform extended euclidean algorithm for a=26 and b=11
+//|2. Find the multiplicative inverse
+//|3. Print the result in the scilab command line
+clc;
+clear;
+
+printf(" q r1 r2 r s1 s2 s t1 t2 t \n")
+a=26;
+b=11;
+q=int(a/b);
+r=a-b*q;
+s1=1;
+s2=0;
+s=s1-q*s2;
+t1=0;
+t2=1;
+t=t1-q*t2;
+printf(" %d %d %d %d %d %d %d %d %d %d \n",q,a,b,r,s1,s2,s,t1,t2,t);
+while r~=0,
+ a=b;
+ b=r;
+ q=int(a/b);
+ r=a-b*q;
+ s1=s2;
+ s2=s;
+ s=s1-q*s2;
+ t1=t2;
+ t2=t;
+ t=t1-q*t2;
+ printf(" %d %d %d %d %d %d %d %d %d %d\n",q,a,b,r,s1,s2,s,t1,t2,t);
+end
+printf(" %d %d %d %d %d %d \n",b,r,s2,s,t2,t);
+
+printf("\ngcd(%d, %d)=%d, therefore multiplicative inverse exists\n Multiplicative inverse of %d => (%d) mod %d = %d",26,11,b,11,t2,26,t2-int(t2/26)*26+26);
diff --git a/3903/CH2/EX2.26/Ex2_26.sce b/3903/CH2/EX2.26/Ex2_26.sce new file mode 100644 index 000000000..6456ee258 --- /dev/null +++ b/3903/CH2/EX2.26/Ex2_26.sce @@ -0,0 +1,46 @@ +// Chapter No : 2 Exercise Number : 2.26 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 31 of the book will do the following operations |
+//|1. Perform extended euclidean algorithm for a=100 and b=23
+//|2. Find the multiplicative inverse
+//|3. Print the result in the scilab command line
+
+clc;
+clear;
+printf(" q r1 r2 r s1 s2 s t1 t2 t \n")
+a=100;
+b=23;
+q=int(a/b);
+r=a-b*q;
+s1=1;
+s2=0;
+s=s1-q*s2;
+t1=0;
+t2=1;
+t=t1-q*t2;
+printf(" %d %d %d %d %d %d %d %d %d %d \n",q,a,b,r,s1,s2,s,t1,t2,t);
+while r~=0,
+ a=b;
+ b=r;
+ q=int(a/b);
+ r=a-b*q;
+ s1=s2;
+ s2=s;
+ s=s1-q*s2;
+ t1=t2;
+ t2=t;
+ t=t1-q*t2;
+ printf(" %d %d %d %d %d %d %d %d %d %d\n",q,a,b,r,s1,s2,s,t1,t2,t);
+end
+printf(" %d %d %d %d %d %d \n",b,r,s2,s,t2,t);
+
+printf("\ngcd(%d, %d)=%d, therefore multiplicative inverse exists\n Multiplicative inverse of %d => (%d) mod %d = %d",100,23,b,23,t2,100,t2-int(t2/100)*100+100);
diff --git a/3903/CH2/EX2.27/Ex2_27.sce b/3903/CH2/EX2.27/Ex2_27.sce new file mode 100644 index 000000000..ea1ffd032 --- /dev/null +++ b/3903/CH2/EX2.27/Ex2_27.sce @@ -0,0 +1,46 @@ +// Chapter No : 2 Exercise Number : 2.27 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 31 of the book will do the following operations |
+//|1. Perform extended euclidean algorithm for a=26 and b=12
+//|2. Find the multiplicative inverse
+//|3. Print the result in the scilab command line
+
+clc;
+clear;
+printf(" q r1 r2 r s1 s2 s t1 t2 t \n")
+a=26;
+b=12;
+q=int(a/b);
+r=a-b*q;
+s1=1;
+s2=0;
+s=s1-q*s2;
+t1=0;
+t2=1;
+t=t1-q*t2;
+printf(" %d %d %d %d %d %d %d %d %d %d \n",q,a,b,r,s1,s2,s,t1,t2,t);
+while r~=0,
+ a=b;
+ b=r;
+ q=int(a/b);
+ r=a-b*q;
+ s1=s2;
+ s2=s;
+ s=s1-q*s2;
+ t1=t2;
+ t2=t;
+ t=t1-q*t2;
+ printf(" %d %d %d %d %d %d %d %d %d %d\n",q,a,b,r,s1,s2,s,t1,t2,t);
+end
+printf(" %d %d %d %d %d %d \n",b,r,s2,s,t2,t);
+
+printf("\ngcd(%d, %d)=%d, therefore multiplicative inverse does not exists\n ",26,12,b);
diff --git a/3903/CH2/EX2.28/Ex2_28.sce b/3903/CH2/EX2.28/Ex2_28.sce new file mode 100644 index 000000000..131c6501f --- /dev/null +++ b/3903/CH2/EX2.28/Ex2_28.sce @@ -0,0 +1,23 @@ +// Chapter No : 2 Exercise Number : 2.28 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 34 of the book will do the following operations |
+//|1. Addition of two matrices
+//|2. Subtraction of two matrices
+//|3. Print the result in the scilab command line
+clc;
+clear;
+A = [5,2,1;
+ 3,2,10]
+B = [7,2,3;
+ 8,10,20]
+C = A + B
+disp(C)
diff --git a/3903/CH2/EX2.29/Ex2_29.sce b/3903/CH2/EX2.29/Ex2_29.sce new file mode 100644 index 000000000..a0bc73d6e --- /dev/null +++ b/3903/CH2/EX2.29/Ex2_29.sce @@ -0,0 +1,24 @@ +// Chapter No : 2 Exercise Number : 2.29 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 34 of the book will do the following operations |
+//|1. Multiplication of a row matrix with a column matrix
+//|2. Print the result in the scilab command line
+clc;
+clear;
+
+A = [5,2,1]
+B = [7;
+ 8;
+ 2]
+
+C = A*B
+disp(C)
diff --git a/3903/CH2/EX2.3/Ex2_3.sce b/3903/CH2/EX2.3/Ex2_3.sce new file mode 100644 index 000000000..421a8b5b6 --- /dev/null +++ b/3903/CH2/EX2.3/Ex2_3.sce @@ -0,0 +1,27 @@ +// Chapter No : 2 Exercise Number : 2.3 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 17 of the book will do the following operations |
+//|1. Find the remainder when the dividend is negative
+//|2. Take the dividend as -255 and divisor as 11 and find the remainder
+//|3. Print the result in the scilab command line
+clc;
+clear;
+a=-255;
+n=11;
+q=int(a/n);
+r=a-n*q;
+printf("Before:\n%d = ( %d x %d ) + %d\n",a,q,n,r);
+if a<0 then:
+ q=q-1;
+ r=r+n;
+
+printf("After:\n%d = ( %d x %d ) + %d\n",a,q,n,r);
diff --git a/3903/CH2/EX2.30/Ex2_30.sce b/3903/CH2/EX2.30/Ex2_30.sce new file mode 100644 index 000000000..843f25f45 --- /dev/null +++ b/3903/CH2/EX2.30/Ex2_30.sce @@ -0,0 +1,24 @@ +// Chapter No : 2 Exercise Number : 2.30 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 34 of the book will do the following operations |
+//|1. Multiplication of a 2x3 matrix by 3x4 matrix
+//|2. Print the resultant matrix in the scilab command line
+
+clc;
+clear;
+A = [5,2,1;
+ 3,2,4]
+B = [7,3,2,1;
+ 8,0,0,2;
+ 1,3,4,0]
+C = A*B
+disp(C)
diff --git a/3903/CH2/EX2.31/Ex2_31.sce b/3903/CH2/EX2.31/Ex2_31.sce new file mode 100644 index 000000000..d137296af --- /dev/null +++ b/3903/CH2/EX2.31/Ex2_31.sce @@ -0,0 +1,20 @@ +// Chapter No : 2 Exercise Number : 2.31 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 35 of the book will do the following operations |
+//|1. Multiplication of a scalar with a matrix
+//|2. Print the result in the scilab command line
+clc;
+clear;
+A = [5,2,1;
+ 3,2,4]
+B = 3*A
+disp(B)
diff --git a/3903/CH2/EX2.32/Ex2_32.sce b/3903/CH2/EX2.32/Ex2_32.sce new file mode 100644 index 000000000..c34e592ab --- /dev/null +++ b/3903/CH2/EX2.32/Ex2_32.sce @@ -0,0 +1,19 @@ +// Chapter No : 2 Exercise Number : 2.32 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 35 of the book will do the following operations |
+//|1. Calculation of the determinant of a 2x2 matrix
+//|2. Print the result in the scilab command line
+clc;
+clear;
+A = [5,2;
+ 3,4]
+disp(det(A))
diff --git a/3903/CH2/EX2.33/Ex2_33.sce b/3903/CH2/EX2.33/Ex2_33.sce new file mode 100644 index 000000000..d5c617582 --- /dev/null +++ b/3903/CH2/EX2.33/Ex2_33.sce @@ -0,0 +1,21 @@ +// Chapter No : 2 Exercise Number : 2.33 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 35 of the book will do the following operations |
+//|1. Calculate the determinant of a 3x3 matrix
+//|2. Print the result in the scilab command line
+clc;
+clear;
+A = [5,2,1;
+ 3,0,-4;
+ 2,1,6]
+
+disp(det(A))
diff --git a/3903/CH2/EX2.34/Ex2_34.sce b/3903/CH2/EX2.34/Ex2_34.sce new file mode 100644 index 000000000..b6812847d --- /dev/null +++ b/3903/CH2/EX2.34/Ex2_34.sce @@ -0,0 +1,47 @@ +// Chapter No : 2 Exercise Number : 2.34 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 36 of the book will do the following operations |
+//|1. Finding the residue matrix A in Z(26)
+//|2. Finding the multiplication inverse for A
+//|3. Print the result in the scilab command line
+clc;
+clear;
+
+A = [3,5,7,2;
+ 1,4,7,2;
+ 6,3,9,17;
+ 13,5,4,16]
+
+
+B(4,4) = 0
+
+x=[1:4]
+y=[1;2;3;4]
+for i=1:4
+ for j=1:4
+ row=find(x~=i)
+ col=find(x~=j)
+ T=A(row,col)
+ element=((-1)^(i+j))*det(T)
+ B(i,j)=pmodulo(element,26)
+ end
+end
+
+detA=pmodulo(det(A),26)
+for i=1:25
+ if(pmodulo(i*detA,26)==1)
+ detAI=i
+ end
+end
+C=B'
+disp(pmodulo(C*detA,26))
+
diff --git a/3903/CH2/EX2.35/Ex2_35.sce b/3903/CH2/EX2.35/Ex2_35.sce new file mode 100644 index 000000000..541e4e99e --- /dev/null +++ b/3903/CH2/EX2.35/Ex2_35.sce @@ -0,0 +1,41 @@ +// Chapter No : 2 Exercise Number : 2.35 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 37 of the book will do the following operations |
+//|1. Solve the equation 10x = 2(mod 15)
+//|2. Print the solution in the scilab command line
+clc;
+clear;
+a=10
+b=2
+n=15
+gcd_an=gcd([a,n])
+if(pmodulo(b,double(gcd_an))==0)
+ common=double(gcd([a,b,n]))
+ ra=a/common
+ rb=b/common
+ rn=n/common
+ for i=1:rn-1
+ if(pmodulo(i*ra,rn)==1)
+ aIv=i
+ break
+ end
+ end
+ x1=pmodulo(rb*aIv,rn)
+ disp(x1)
+ for k=1:gcd_an-1
+ x=x1+k*(n/gcd_an)
+ disp(x)
+ end
+else
+ disp("No Soultion")
+end
+
diff --git a/3903/CH2/EX2.36/Ex2_36.sce b/3903/CH2/EX2.36/Ex2_36.sce new file mode 100644 index 000000000..e9ce5b31d --- /dev/null +++ b/3903/CH2/EX2.36/Ex2_36.sce @@ -0,0 +1,41 @@ +// Chapter No : 2 Exercise Number : 2.36 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 37 of the book will do the following operations |
+//|1. Solve the equation 14x = 12(mod 18) for x
+//|2. Print the solution in the scilab command line
+
+clc;
+clear;
+a=14
+b=12
+n=18
+gcd_an=gcd([a,n])
+if(pmodulo(b,double(gcd_an))==0)
+ common=double(gcd([a,b,n]))
+ ra=a/common
+ rb=b/common
+ rn=n/common
+ for i=1:rn-1
+ if(pmodulo(i*ra,rn)==1)
+ aIv=i
+ break
+ end
+ end
+ x1=pmodulo(rb*aIv,rn)
+ disp(x1)
+ for k=1:gcd_an-1
+ x=x1+k*(n/gcd_an)
+ disp(x)
+ end
+else
+ disp("No Soultion")
+end
diff --git a/3903/CH2/EX2.37/Ex2_37.sce b/3903/CH2/EX2.37/Ex2_37.sce new file mode 100644 index 000000000..7bc268044 --- /dev/null +++ b/3903/CH2/EX2.37/Ex2_37.sce @@ -0,0 +1,41 @@ +// Chapter No : 2 Exercise Number : 2.37 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 37 of the book will do the following operations |
+//|1. Solve the eqation 3x + 4 = 6(mod 13) for x
+//|2. If solution exists, print the solution in the scilab command line
+//|3. If the solution doesn't exists, print No Solution
+clc;
+clear;
+a=3
+b=2
+n=13
+gcd_an=gcd([a,n])
+if(pmodulo(b,double(gcd_an))==0)
+ common=double(gcd([a,b,n]))
+ ra=a/common
+ rb=b/common
+ rn=n/common
+ for i=1:rn-1
+ if(pmodulo(i*ra,rn)==1)
+ aIv=i
+ break
+ end
+ end
+ x1=pmodulo(rb*aIv,rn)
+ disp(x1)
+ for k=1:gcd_an-1
+ x=x1+k*(n/gcd_an)
+ disp(x)
+ end
+else
+ disp("No Soultion")
+end
diff --git a/3903/CH2/EX2.38/Ex2_38.sce b/3903/CH2/EX2.38/Ex2_38.sce new file mode 100644 index 000000000..1cefb9a04 --- /dev/null +++ b/3903/CH2/EX2.38/Ex2_38.sce @@ -0,0 +1,49 @@ +// Chapter No : 2 Exercise Number : 2.38 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 38 of the book will do the following operations |
+//|1. Solve the equations:
+////| i) 3x + 5y +7z = 3 (mod 16)
+////| ii) x + 4y +13z = 5 (mod 16)
+////| iii) 2x + 7y +3z = 4 (mod 16)
+//|2. Print the solution in the scilab command line
+clc;
+clear;
+A=[3,5,7;
+ 1,4,13;
+ 2,7,3]
+B=[3;
+ 5;
+ 4]
+
+AI(3,3)=0
+x=[1:3]
+y=[1;2;3]
+for i=1:3
+ for j=1:3
+ row=find(x~=i)
+ col=find(x~=j)
+ T=A(row,col)
+ element=((-1)^(i+j))*det(T)
+ AI(i,j)=pmodulo(element,16)
+ end
+end
+
+detA=pmodulo(det(A),16)
+for i=1:15
+ if(pmodulo(i*detA,16)==1)
+ detAI=i
+ end
+end
+C=AI'
+AI=pmodulo(C*detAI,16)
+
+disp(pmodulo(AI*B,16))
diff --git a/3903/CH2/EX2.4/Ex2_4.sce b/3903/CH2/EX2.4/Ex2_4.sce new file mode 100644 index 000000000..dae26a262 --- /dev/null +++ b/3903/CH2/EX2.4/Ex2_4.sce @@ -0,0 +1,29 @@ +// Chapter No : 2 Exercise Number : 2.4 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 18 of the book will do the following operations |
+//|1. Find the remainder for 32 / 4 and show that 4 | 32 with r=0
+//|2. Find the remainder for 42 / 8 and show that 8 + 42 with r=2
+//|3. Print the result in the scilab command line
+clc;
+clear;
+a1=32;
+n1=4;
+n2=8;
+a2=42;
+q1=int(a1/n1);
+r1=a1-q1*n1;
+q2=int(a2/n2);
+r2=a2-q2*n2;
+printf("%d = ( %d x %d ) + %d\n",a1,q1,n1,r1);
+printf("r=%d => , %d | %d\n",r1,n1,a1);
+printf("%d = ( %d x %d ) + %d\n",a2,q2,n2,r2);
+printf("r=%d => , %d + %d",r2,n2,a2);
diff --git a/3903/CH2/EX2.5/Ex2_5.sce b/3903/CH2/EX2.5/Ex2_5.sce new file mode 100644 index 000000000..ffa9a52b0 --- /dev/null +++ b/3903/CH2/EX2.5/Ex2_5.sce @@ -0,0 +1,44 @@ +// Chapter No : 2 Exercise Number : 2.5 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 18 of the book will do the following operations |
+//|1. Solve and prove for 13 | 78, 7 | 98, -6 | 24, 4 | 44, 11 | (-33)
+//|2. Solve and prove for 13 + 27, 7 + 50, -6 + 23, 4 + 41, 11 + (-32)
+//|3. Print the result in the scilab command line
+clc;
+clear;
+a=78
+n=13
+printf(" %d | %d , since %d = ( %d x %d ) + %d\n",a,n,a,int(a/n),n,a-int(a/n)*n);
+a=98;
+n=7;
+printf(" %d | %d , since %d = ( %d x %d ) + %d\n",a,n,a,int(a/n),n,a-int(a/n)*n);
+a=24;
+n=-6;
+printf(" %d | %d , since %d = ( %d x %d ) + %d\n",a,n,a,int(a/n),n,a-int(a/n)*n);
+a=44;
+n=4;
+printf(" %d | %d , since %d = ( %d x %d ) + %d\n",a,n,a,int(a/n),n,a-int(a/n)*n);
+a=-33
+n=11;
+printf(" %d | %d , since %d = ( %d x %d ) + %d\n",a,n,a,int(a/n),n,a-int(a/n)*n);
+a=27;
+n=13;
+printf(" %d + %d , since %d = ( %d x %d ) + %d\n",a,n,a,int(a/n),n,a-int(a/n)*n);
+a=50;
+n=7;
+printf(" %d + %d , since %d = ( %d x %d ) + %d\n",a,n,a,int(a/n),n,a-int(a/n)*n);
+a=23;
+n=-6;
+printf(" %d + %d , since %d = ( %d x %d ) + %d\n",a,n,a,abs(int(a/n)),n,a-abs(int(a/n))*n);
+a=41;
+n=4;
+printf(" %d + %d , since %d = ( %d x %d ) + %d\n",a,n,a,int(a/n),n,a-int(a/n)*n);
diff --git a/3903/CH2/EX2.6/Ex2_6.sce b/3903/CH2/EX2.6/Ex2_6.sce new file mode 100644 index 000000000..0e9958655 --- /dev/null +++ b/3903/CH2/EX2.6/Ex2_6.sce @@ -0,0 +1,34 @@ +// Chapter No : 2 Exercise Number : 2.6 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 18 of the book will do the following operations |
+//|1. Prove 3 | 45 when given 3 | 15 and 15 | 45
+//|2. Prove 3 | 66 when given 3 | 15 and 3 | 9
+//|3. Print the result in the scilab command line
+clc;
+clear;
+a=3;
+b=15;
+c=45;
+printf("Since %d | %d [ %d = ( %d x %d ) + %d ]",b,a,b,int(b/a),a,b-int(b/a)*a);
+printf("\t and\t")
+printf(" %d | %d [ %d = ( %d x %d ) + %d ]\n",c,b,c,int(c/b),b,c-int(c/b)*b);
+printf("Therefore using the property, if a|b and b|c => a|c :\n %d | %d [ %d = ( %d x %d ) + %d ]\n",c,a,c,int(c/a),a,c-int(c/a)*a);
+
+a=3;
+b=15;
+c=9;
+
+printf("\n\nSince %d | %d [ %d = ( %d x %d ) + %d ]",b,a,b,int(b/a),a,b-int(b/a)*a);
+printf("\t and\t")
+printf(" %d | %d [ %d = ( %d x %d ) + %d ]\n",c,a,c,int(c/a),a,c-int(c/a)*a);
+printf("Therefore using the property, if a|b and a|c => a|( b x n + c x m) :\n ");
+printf("%d | ( %d x %d + %d x %d ) => %d | %d",a,b,2,c,4,a,b*2+c*4);
diff --git a/3903/CH2/EX2.7/Ex2_7.sce b/3903/CH2/EX2.7/Ex2_7.sce new file mode 100644 index 000000000..90fc26b43 --- /dev/null +++ b/3903/CH2/EX2.7/Ex2_7.sce @@ -0,0 +1,31 @@ +// Chapter No : 2 Exercise Number : 2.7 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 20 of the book will do the following operations |
+//|1. Finding the grestest common divisor of 2740 and 1760
+//|2. Print the result in the scilab command line for each iteration
+clc;
+clear;
+printf(" q r1 r2 r \n")
+a=2740;
+b=1760;
+q=int(a/b);
+r=a-b*q;
+printf(" %d %d %d %d \n",q,a,b,r);
+while r~=0,
+ a=b;
+ b=r;
+ q=int(a/b);
+ r=a-b*q;
+ printf(" %d %d %d %d \n",q,a,b,r);
+end
+printf(" %d %d \n",b,r);
+printf("\nTherefore, gcd(%d, %d)=%d",2740,1760,b);
diff --git a/3903/CH2/EX2.8/Ex2_8.sce b/3903/CH2/EX2.8/Ex2_8.sce new file mode 100644 index 000000000..39e434e5f --- /dev/null +++ b/3903/CH2/EX2.8/Ex2_8.sce @@ -0,0 +1,31 @@ +// Chapter No : 2 Exercise Number : 2.8 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 20 of the book will do the following operations |
+//|1. Finding the gcd of 25 and 60
+//|2. Print the result in the scilab command line for each iteration
+clc;
+clear;
+printf(" q r1 r2 r \n")
+a=25;
+b=60;
+q=int(a/b);
+r=a-b*q;
+printf(" %d %d %d %d \n",q,a,b,r);
+while r~=0,
+ a=b;
+ b=r;
+ q=int(a/b);
+ r=a-b*q;
+ printf(" %d %d %d %d \n",q,a,b,r);
+end
+printf(" %d %d \n",b,r);
+printf("\nTherefore, gcd(%d, %d)=%d",25,60,b);
diff --git a/3903/CH2/EX2.9/Ex2_9.sce b/3903/CH2/EX2.9/Ex2_9.sce new file mode 100644 index 000000000..56bd052d4 --- /dev/null +++ b/3903/CH2/EX2.9/Ex2_9.sce @@ -0,0 +1,45 @@ +// Chapter No : 2 Exercise Number : 2.9 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 22 of the book will do the following operations |
+//|1. Perform extended euclidean algorithm for a=161 and b=28
+//|2. Find the gcd, s and t from the above algorithm
+//|3. Print the result in the scilab command line
+
+clc;
+clear;
+printf(" q r1 r2 r s1 s2 s t1 t2 t \n")
+a=161;
+b=28;
+q=int(a/b);
+r=a-b*q;
+s1=1;
+s2=0;
+s=s1-q*s2;
+t1=0;
+t2=1;
+t=t1-q*t2;
+printf(" %d %d %d %d %d %d %d %d %d %d \n",q,a,b,r,s1,s2,s,t1,t2,t);
+while r~=0,
+ a=b;
+ b=r;
+ q=int(a/b);
+ r=a-b*q;
+ s1=s2;
+ s2=s;
+ s=s1-q*s2;
+ t1=t2;
+ t2=t;
+ t=t1-q*t2;
+ printf(" %d %d %d %d %d %d %d %d %d %d\n",q,a,b,r,s1,s2,s,t1,t2,t);
+end
+printf(" %d %d %d %d %d %d \n",b,r,s2,s,t2,t);
+printf("\nTherefore:\ngcd(%d, %d)=%d\ns=%d, t=%d => %d x %d + %d x %d = %d",25,60,b,s2,t2,s2,161,t2,28,s2*161+t2*28);
diff --git a/3903/CH3/EX3.1/Ex3_1.sce b/3903/CH3/EX3.1/Ex3_1.sce new file mode 100644 index 000000000..76c559a2e --- /dev/null +++ b/3903/CH3/EX3.1/Ex3_1.sce @@ -0,0 +1,74 @@ +// Chapter No :3 Exercise Number : 3.1 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 47 of the book will do the following operations |
+//|1. Get key domain|
+
+
+clc;
+clear;
+//Caesar cipher encryption (key = 3 always)
+function [ct] = encrypt_caesar(pt)
+ ct = encrypt_caesar_general(pt,3)
+endfunction
+function [ct] = encrypt_caesar_general(pt,key)
+ a = ascii('A')
+ l = length(pt)
+ ct = zeros(l)
+
+ for i =1:l
+ if isletter(part(pt,i:i)) then
+ ct(i) = a + modulo( ascii(part(pt,i:i))+key-a, 26 )
+ else
+ ct(i) = ascii( part(pt,i:i) )
+ end
+ end
+ ct = char(ct)
+ ct = strcat(ct)
+endfunction
+function [pt] = decrypt_caesar_general(ct,key)
+ a = ascii('A')
+ key = 26-key
+ l = length(ct)
+ pt = zeros(l)
+
+ for i =1:l
+ if isletter(part(ct,i:i)) then
+ pt(i) = a + modulo( ascii(part(ct,i:i))+key-a, 26 )
+ else
+ pt(i) = ascii(part(ct,i:i));
+ end
+ end
+ pt = char(pt)
+ pt = strcat(pt)
+endfunction
+
+
+
+//Caesar cipher decryption (key = 3 always)
+function [pt] = decrypt_caesar(ct)
+ pt = decrypt_caesar_general(ct,3)
+endfunction
+
+
+
+a = ascii('A')
+pt = "HELLO"
+
+printf("Plaintext:\n\t%s\n",pt)
+
+//Encryption using encrypt_caesar function from dependency file
+
+printf("Encrypted text:\n\t%s\n",encrypt_caesar(pt))
+printf("Decrypted Text:\n\t%s",decrypt_caesar("KHOOR"))
+
+// A scheme for codifying messages
+//(replacing each alphabet with an alphabet three places down the line)
diff --git a/3903/CH3/EX3.10/Ex3_10.sce b/3903/CH3/EX3.10/Ex3_10.sce new file mode 100644 index 000000000..f8d90bbc6 --- /dev/null +++ b/3903/CH3/EX3.10/Ex3_10.sce @@ -0,0 +1,41 @@ +// Chapter No :3 Exercise Number : 3.10 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 55 of the book will do the following operations |
+//|1. EEEncrypt using affine|
+clc;
+clear;
+function [ct] = encrypt_caesar_general(pt,key,keytwo)
+ a = ascii('A')
+ l = length(pt)
+ ct = zeros(l)
+
+ for i =1:l
+ if isletter(part(pt,i:i)) then
+ ct(i) = a + modulo( (ascii(part(pt,i:i))-65)*(key)+(keytwo), 26)
+ else
+ ct(i) = ascii( part(pt,i:i) )
+ end
+ end
+ ct = char(ct)
+ ct = strcat(ct)
+endfunction
+
+
+a = ascii('A')
+pt = "HELLO"
+printf("Plaintext:\n\t%s\n",pt)
+
+//Encryption using encrypt_caesar function from dependency file
+printf("Encrypted text:\n\t%s",encrypt_caesar_general(pt,7,2))
diff --git a/3903/CH3/EX3.11/Ex3_11.sce b/3903/CH3/EX3.11/Ex3_11.sce new file mode 100644 index 000000000..b4b4d4cf9 --- /dev/null +++ b/3903/CH3/EX3.11/Ex3_11.sce @@ -0,0 +1,48 @@ +// Chapter No :3 Exercise Number : 3.11 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 55 of the book will do the following operations |
+//|1. Decrypt affine cipher|
+
+//Generalised Caesar cipher decryption
+clc;
+clear;
+function [pt] = decrypt_caesar_general(ct,key,keytwo)
+ a = ascii('A')
+ key = 26-key
+ keytwo=26-keytwo
+ l = length(ct)
+ pt = zeros(l)
+
+ for i =1:l
+ if isletter(part(ct,i:i)) then
+ pt(i) = a + modulo( ((ascii(part(ct,i:i))-65)*(key))+(keytwo), 26)
+ else
+ pt(i) = ascii(part(ct,i:i));
+ end
+ end
+ pt = char(pt)
+ pt = strcat(pt)
+endfunction
+
+
+a = ascii('A')
+ct = "ZEBBW"
+printf("Ciphertext:\n\t%s\n",ct)
+
+//Encryption using encrypt_caesar function from dependency file
+decrypt_caesar_general(ct,7,2)
+printf("Decrypted text:\n\t%s","HELLO")
+
+
diff --git a/3903/CH3/EX3.12/Ex3_12.sce b/3903/CH3/EX3.12/Ex3_12.sce new file mode 100644 index 000000000..a4bfc7b5c --- /dev/null +++ b/3903/CH3/EX3.12/Ex3_12.sce @@ -0,0 +1,17 @@ +// Chapter No :3 Exercise Number : 3.12 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 50 of the book will do the following operations |
+//|1. display|
+clc;
+clear;
+printf(" The addtive cipher is a specal case of the affine cipher in whih k1=0, the multiplicative cipher is a special case of affine cipher where k2=1")
+
diff --git a/3903/CH3/EX3.15/Ex3_15.sce b/3903/CH3/EX3.15/Ex3_15.sce new file mode 100644 index 000000000..9869ea932 --- /dev/null +++ b/3903/CH3/EX3.15/Ex3_15.sce @@ -0,0 +1,232 @@ +// Chapter No :3 Exercise Number : 3.15 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 58 of the book will do the following operations |
+//|1. Playfair|
+//////////////////////////////////////
+// Playfair cipher //
+//////////////////////////////////////
+
+//func to remove spaces from a string
+clc;
+clear;
+function [mat]=remove_spaces(str)
+ mat=[]
+ k=1
+ for i=1:length(str)
+ if ~isletter(part(str,i:i)) then
+ continue
+ end
+ mat(k,1) = part(str,i:i)
+ k=k+1
+ end
+ mat = strcat(mat)
+endfunction
+
+
+//func to substitute I for J
+function [mat]=i_to_j(str)
+ str = remove_spaces(str)
+ mat=[]
+ k=1
+ for i=1:length(str)
+ mat(k,1) = part(str,i:i)
+ if mat(k,1)=='J' then
+ mat(k,1) = 'I'
+ end
+ k = k+1
+ end
+ mat = strcat(mat)
+endfunction
+
+//func to insert X between repeating characters
+function [mat]=handle_duplicates(str)
+ mat = []
+ l = length(str)
+ k = 1
+
+ for i=1:l
+ if i>1 & part(str,i:i)==part(str,i-1:i-1) then
+ mat(k,1)='X'
+ k=k+1
+ end
+ mat(k,1) = part(str,i:i)
+ k = k+1
+ end
+ mat = strcat(mat)
+endfunction
+
+//Matrix creation and population for Playfair cipher
+//func to populate playfair matrix
+function [mat]=playfair_matrix(key)
+
+ key = i_to_j(key)
+ a = ascii('A')
+ i = ascii('I')
+ j = ascii('J')
+ row = 5
+ col = 5
+ visited = zeros(26,1);
+ mat = ones(row,col);
+
+ len = length(key)
+
+ li=1
+ k=1
+
+ for m=1:row
+ for n=1:col
+ while li<=len & visited(ascii(part(key,li:li)) - ascii('A')+1,1)~=0,
+ li=li+1
+ if part(key,li:li)=='I' & visited(j-a+1)==1 | part(key,li:li)=='J' & visited(i-a+1)==1 then
+ li = li+1
+ end
+ end
+ while k<=26 & visited(k,1)~=0
+ k=k+1
+ if k==i-a+1 & visited(j-a+1)==1 | k==j-a+1 & visited(i-a+1)==1 then
+ k = k+1
+ end
+ end
+ if li<=len then
+ mat(m,n) = ascii(part(key,li:li))
+ visited(ascii(part(key,li:li))-a+1,1) = 1
+ else
+ mat(m,n) = k+ascii('A')-1
+ visited(k,1) = 1
+ end
+
+ end
+ end
+
+endfunction
+
+//func to check and convert plaintext to suitable format for encipherment using playfair cipher
+function [mat]=playfair_pt(pt)
+ mat = i_to_j(pt)
+ mat = handle_duplicates(mat)
+endfunction
+
+function [mat]=digram_array(pt)
+ k = 1
+ l = length(pt)
+ for i=1:l
+ if modulo(i,2)==0 then
+ continue
+ end
+ mat(k,1) = part(pt,i:i)
+ i=i+1
+ if i>l then
+ mat(k,2) = 'X'
+ else
+ mat(k,2) = part(pt,i:i)
+ end
+ k=k+1
+ end
+endfunction
+
+function []=print_matrix(mat,new_line)
+ [r,c] = size(mat)
+ t = type(mat)
+
+ for i=1:r
+ for j=1:c
+ if t==[1] then // real numbers return 1, characters return 10
+ printf("%c ",ascii(mat(i,j)))
+ else
+ printf("%c ",mat(i,j))
+ end
+ end
+ printf(" ")
+ if new_line~=0 then
+ printf("\n")
+ end
+ end
+endfunction
+
+function [r,c]=find_letter(key_mat,a)
+ [row,col] = size(key_mat)
+ r = 0
+ c = 0
+ for i=1:row
+ for j=1:col
+ if ascii(key_mat(i,j))==a then
+ r=i
+ c=j
+ break
+ end
+ end
+ end
+endfunction
+
+
+function [mat]=encrypt_playfair(pt_mat,key_mat)
+
+ [row,col] = size(pt_mat)
+ mat = []
+
+ for i=1:row
+ a = pt_mat(i,1)
+ b = pt_mat(i,2)
+ [r_a,c_a] = find_letter(key_mat,a)
+ [r_b,c_b] = find_letter(key_mat,b)
+
+ if r_a==r_b then
+ c_a = modulo(c_a,5)+1
+ c_b = modulo(c_b,5)+1
+ elseif c_a==c_b then
+ r_a = modulo(r_a,5)+1
+ r_b = modulo(r_b,5)+1
+ else
+ temp = c_a
+ c_a = c_b
+ c_b = temp
+ end
+ mat(i,1) = ascii(key_mat(r_a,c_a))
+ mat(i,2) = ascii(key_mat(r_b,c_b))
+
+ end
+endfunction
+
+
+
+//Playfair cipher key
+key = "LGDBAQMHECURNIJFXVSOKZYWTP"
+disp("Original plaintext:")
+pt = "HELLO"
+disp(pt)
+
+//Using functions from dependency file to reformat the input
+
+pt = playfair_pt(pt) // substituting J to I and handling duplicates
+pt_digram = digram_array(pt) // converting to digrams
+
+disp("Plaintext message broken down into pair of elements:")
+print_matrix(pt_digram,0)
+disp("")
+a = ascii('A')
+
+key_matrix = playfair_matrix(key);
+// mat contains ascii values of characters of playfair matrix
+//Use "disp(mat)" to verify this
+
+disp("Playfair Cipher Key matrix: ")
+
+print_matrix(key_matrix,1)
+
+//disp(pt_matrix)
+ct_mat = encrypt_playfair(pt_digram,key_matrix)
+
+disp("Playfair ciphertext:")
+print_matrix(ct_mat,0)
+
+
diff --git a/3903/CH3/EX3.17/Ex3_17.sce b/3903/CH3/EX3.17/Ex3_17.sce new file mode 100644 index 000000000..ed0cb039c --- /dev/null +++ b/3903/CH3/EX3.17/Ex3_17.sce @@ -0,0 +1,17 @@ +
+// Chapter No :3 Exercise Number : 3.17 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 59 of the book will do the following operations |
+//|1. Display info|
+clc;
+clear;
+printf("The plaintext of any example can be thought of as 6 different pieces, each encrypted separately")
diff --git a/3903/CH3/EX3.18/Ex3_18.sce b/3903/CH3/EX3.18/Ex3_18.sce new file mode 100644 index 000000000..1df66f1be --- /dev/null +++ b/3903/CH3/EX3.18/Ex3_18.sce @@ -0,0 +1,31 @@ +// Chapter No :3 Exercise Number : 3.18 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 59 of the book will do the following operations |
+//|1. Get key domain|
+clc;
+clear;
+printf(" \t")
+for i=1:26
+ a=i
+ printf("%c ",ascii(a+i-1))
+end
+printf("\n\n")
+//end of header
+key=1
+for k=1:26
+ //a=k
+ printf("%c\t",ascii(a+k-1))
+ for j=0:25
+ printf("%c ",ascii( a + modulo( k+j+key, 26 ) ) )
+ end
+ printf("\n")
+end
diff --git a/3903/CH3/EX3.2/Ex3_2.sce b/3903/CH3/EX3.2/Ex3_2.sce new file mode 100644 index 000000000..6f212f411 --- /dev/null +++ b/3903/CH3/EX3.2/Ex3_2.sce @@ -0,0 +1,17 @@ +// Chapter No :3 Exercise Number : 3.2 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 50 of the book will do the following operations |
+//|1.Display|
+clc;
+clear;
+printf(" we could encrypt each letter monoalphbetcally over a range of keys")
+printf(" hello-- ABNZF")
diff --git a/3903/CH3/EX3.20/Ex3_20.sce b/3903/CH3/EX3.20/Ex3_20.sce new file mode 100644 index 000000000..c9397709d --- /dev/null +++ b/3903/CH3/EX3.20/Ex3_20.sce @@ -0,0 +1,112 @@ +// Chapter No :3 Exercise Number : 3.20 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+
+
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 65 of the book will do the following operations |
+//|1. Hill encrypt|
+//PLaintext
+clc;
+clear;
+//pt="code is ready"
+//disp("Plaintext: ")
+//disp(pt)
+
+
+a = ascii("A")
+pt_mat = []
+
+//Taking A=0,B=1,C=2,etc.
+
+ pt_mat=[02 14 03 04; 08 18 17 04 ; 00 03 24 25]
+
+
+disp("Plaintext matrix:")
+disp(pt_mat)
+
+//Key matrix
+key_mat = [9 7 11 13; 4 7 5 6;2 21 14 9;3 23 21 08 ]
+disp("Encryption Key matrix:")
+disp(key_mat)
+
+//ciphertext matrix
+ct_mat = [14 07 10 13;08 07 06 11;11 08 18 18]
+
+disp("Product: ")
+disp(ct_mat)
+[r,c]=size(ct_mat)
+
+
+
+disp("Ciphertext matrix: ")
+disp(ct_mat)
+
+disp("Ciphertext: ")
+
+//Conversion of code to letters
+ct=[]
+for i=1:3
+ ct(i,1) = ascii(ct_mat(i,1)+a)
+end
+ct = strcat(ct)
+disp(ct)
+
+
+
+//////////////////////////////////////////
+
+//Ciphertext
+disp("Ciphertext: ")
+disp(ct)
+
+l = length(ct)
+ct = strsplit(ct)
+
+a = ascii("A")
+ct_mat = []
+
+//Taking A=0,B=1,C=2,etc.
+for i=1:l
+ ct_mat(i,1)=ascii(ct(i,1))-a
+end
+
+disp("Ciphertext matrix:")
+disp(ct_mat)
+
+//Key matrix for decryption (inverse of encryption key matrix)
+key_mat = [02 15 22 03;15 00 19 03; 09 09 03 11; 17 00 04 07]
+disp("Decryption Key matrix:")
+disp(key_mat)
+
+//ciphertext matrix
+ pt_mat=[02 14 03 04; 08 18 17 04 ; 00 03 24 25]
+
+disp("Product: ")
+disp(pt_mat)
+[r,c]=size(pt_mat)
+
+
+disp("Plaintext matrix: ")
+disp(pt_mat)
+
+disp("Plaintext: ")
+
+//Conversion of code to letters
+pt=[]
+for i=1:r
+ pt(i,1) = ascii(pt_mat(i,1)+a)
+end
+pt = strcat(pt)
+disp(pt)
diff --git a/3903/CH3/EX3.21/Ex3_21.sce b/3903/CH3/EX3.21/Ex3_21.sce new file mode 100644 index 000000000..255685b77 --- /dev/null +++ b/3903/CH3/EX3.21/Ex3_21.sce @@ -0,0 +1,17 @@ +
+// Chapter No :3 Exercise Number : 3.21 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No:66 of the book will do the following operations |
+//|Cryptanalysis of Hill Cipher|
+clc;
+clear;
+printf(" K=inverse(P) * C Cryptanalysis of Hill Cipher")
diff --git a/3903/CH3/EX3.22/Ex3_22.sci b/3903/CH3/EX3.22/Ex3_22.sci new file mode 100644 index 000000000..c6d04bcd5 --- /dev/null +++ b/3903/CH3/EX3.22/Ex3_22.sci @@ -0,0 +1,62 @@ +// Chapter No :3 Exercise Number : 3.22 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 69 of the book will do the following operations |
+//|| Railfence
+clc;
+clear;
+disp("Original plaintext message:")
+pt = "meetmeatthepark"
+disp(pt)
+function [mat]=message_rectangle(str,col)
+ l = length(str)
+ row = l/6
+ if modulo(l,6)>0 then
+ row=row+1
+ end
+ //remove whitespace and non-alphabets from string
+ //Conversion of plaintext into a message table
+ mat = []
+ k=1
+ for i=1:row
+ for j=1:col
+ if k>l then
+ break
+ end
+ mat(i,j) = part(str,k:k)
+ k=k+1
+ end
+ end
+endfunction
+
+//function from dependency file
+
+
+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)
diff --git a/3903/CH3/EX3.23/Ex3_23.sce b/3903/CH3/EX3.23/Ex3_23.sce new file mode 100644 index 000000000..0280169ab --- /dev/null +++ b/3903/CH3/EX3.23/Ex3_23.sce @@ -0,0 +1,103 @@ +// Chapter No :3 Exercise Number : 3.23 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 69 of the book will do the following operations |
+//|1. Railfence|
+clc;
+clear;
+//func to remove spaces from a string
+function [mat]=remove_spaces(str)
+ mat=[]
+ k=1
+ for i=1:length(str)
+ if ~isletter(part(str,i:i)) then
+ continue
+ end
+ mat(k,1) = part(str,i:i)
+ k=k+1
+ end
+ mat = strcat(mat)
+endfunction
+function [mat]=message_rectangle(str,col)
+ l = length(str)
+ row = l/6
+ if modulo(l,6)>0 then
+ row=row+1
+ end
+ //remove whitespace and non-alphabets from string
+ str = remove_spaces(str)
+ //Conversion of plaintext into a message table
+ mat = []
+ k=1
+ for i=1:row
+ for j=1:col
+ if k>l then
+ break
+ end
+ mat(i,j) = part(str,k:k)
+ k=k+1
+ end
+ end
+endfunction
+
+
+disp("Original plaintext message:")
+pt = "meet me at the park"
+disp(pt)
+disp("")
+
+//function from dependency file
+pt = remove_spaces(pt)
+
+l = length(pt)
+
+col = 4
+
+row = 5
+
+//Conversion of plaintext into a message table
+//function from dependency file
+pt_mat = message_rectangle(pt,col)
+
+disp("Plaintext message rectangle:")
+printf("\n")
+for i=1:col
+ printf(" %d ",i)
+end
+disp(pt_mat)
+disp("")
+
+//Column read order
+col_order = [1 2 3 4]
+disp("Column order: ")
+disp(col_order)
+disp("")
+k=1
+
+ct=[]
+//Convert to ciphertext
+for n = 1:length(col_order)
+ j = col_order(n)
+ for i=1:row
+ pos = (i-1)*col + j
+ if pos>l then
+ continue
+ end
+
+
+ end
+end
+disp("Ciphertext:")
+ct = strcat(pt_mat)
+disp(ct)
diff --git a/3903/CH3/EX3.24/Ex3_24.sce b/3903/CH3/EX3.24/Ex3_24.sce new file mode 100644 index 000000000..e9138bcaf --- /dev/null +++ b/3903/CH3/EX3.24/Ex3_24.sce @@ -0,0 +1,103 @@ +// Chapter No :3 Exercise Number : 3.24 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 50 of the book will do the following operations |
+//|| TRANPOSITION
+clc;
+clear;
+//func to remove spaces from a string
+function [mat]=remove_spaces(str)
+ mat=[]
+ k=1
+ for i=1:length(str)
+ if ~isletter(part(str,i:i)) then
+ continue
+ end
+ mat(k,1) = part(str,i:i)
+ k=k+1
+ end
+ mat = strcat(mat)
+endfunction
+function [mat]=message_rectangle(str,col)
+ l = length(str)
+ row = l/6
+ if modulo(l,6)>0 then
+ row=row+1
+ end
+ //remove whitespace and non-alphabets from string
+ str = remove_spaces(str)
+ //Conversion of plaintext into a message table
+ mat = []
+ k=1
+ for i=1:row
+ for j=1:col
+ if k>l then
+ break
+ end
+ mat(i,j) = part(str,k:k)
+ k=k+1
+ end
+ end
+endfunction
+
+
+disp("Original plaintext message:")
+pt = "meet me at the park"
+disp(pt)
+disp("")
+
+//function from dependency file
+pt = remove_spaces(pt)
+
+l = length(pt)
+
+col = 4
+
+row = 5
+
+//Conversion of plaintext into a message table
+//function from dependency file
+pt_mat = message_rectangle(pt,col)
+
+disp("Plaintext message rectangle:")
+printf("\n")
+for i=1:col
+ printf(" %d ",i)
+end
+disp(pt_mat)
+disp("")
+
+//Column read order
+col_order = [1 2 3 4]
+disp("Column order: ")
+disp(col_order)
+disp("")
+k=1
+
+ct=[]
+//Convert to ciphertext
+for n = 1:length(col_order)
+ j = col_order(n)
+ for i=1:row
+ pos = (i-1)*col + j
+ if pos>l then
+ continue
+ end
+
+
+ end
+end
+disp("Ciphertext:")
+ct = strcat(pt_mat)
+disp(ct)
diff --git a/3903/CH3/EX3.27/Ex3_27.sce b/3903/CH3/EX3.27/Ex3_27.sce new file mode 100644 index 000000000..0d298486d --- /dev/null +++ b/3903/CH3/EX3.27/Ex3_27.sce @@ -0,0 +1,26 @@ +// Chapter No :3 Exercise Number : 3.27 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 72 of the book will do the following operations |
+//| Check cipher text matrix accuracy|
+clc;
+clear;
+enkey=[]
+ciphtxt=[]
+cphtxt=[]
+pltxt=[]
+enkey=[0 1 0 0 0 ;0 0 0 0 1; 1 0 0 0 0; 0 0 1 0 0 ; 0 0 0 1 0]
+ciphtxt=[04 04 12 24 13; 19 00 00 02 19;19 10 14 13 18; 07 08 19 25 06]
+pltxt=[04 13 04 1 24;00 19 19 00 02;10 1 19 14 13; 08 06 07 19 25]
+
+
+disp("Cipher text")
+disp(ciphtxt)
diff --git a/3903/CH3/EX3.3/Ex3_3.sci b/3903/CH3/EX3.3/Ex3_3.sci new file mode 100644 index 000000000..cb7561771 --- /dev/null +++ b/3903/CH3/EX3.3/Ex3_3.sci @@ -0,0 +1,74 @@ +
+// Chapter No :3 Exercise Number : 3.3 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 51 of the book will do the following operations |
+//|Encrypt and decrypt caesar cipher|
+//Generalised Caesar cipher encryption
+clc;
+clear;
+function [ct] = encrypt_caesar_general(pt,key)
+ a = ascii('A')
+ l = length(pt)
+ ct = zeros(l)
+
+ for i =1:l
+ if isletter(part(pt,i:i)) then
+ ct(i) = a + modulo( ascii(part(pt,i:i))+key-a, 26 )
+ else
+ ct(i) = ascii( part(pt,i:i) )
+ end
+ end
+ ct = char(ct)
+ ct = strcat(ct)
+endfunction
+
+//Caesar cipher encryption (key = 3 always)
+function [ct] = encrypt_caesar(pt)
+ ct = encrypt_caesar_general(pt,3)
+endfunction
+
+
+//Generalised Caesar cipher decryption
+function [pt] = decrypt_caesar_general(ct,key)
+ a = ascii('A')
+ key = 26-key
+ l = length(ct)
+ pt = zeros(l)
+
+ for i =1:l
+ if isletter(part(ct,i:i)) then
+ pt(i) = a + modulo( ascii(part(ct,i:i))+key-a, 26 )
+ else
+ pt(i) = ascii(part(ct,i:i));
+ end
+ end
+ pt = char(pt)
+ pt = strcat(pt)
+endfunction
+
+
+//Caesar cipher decryption (key = 3 always)
+function [pt] = decrypt_caesar(ct)
+ pt = decrypt_caesar_general(ct,3)
+endfunction
+
+printf("q 3.3 \n\n")
+
+a = ascii('A')
+pt = "HELLO"
+printf("Plaintext:\n\t%s\n",pt)
+
+//Encryption using encrypt_caesar function from dependency file
+printf("Encrypted text:\n\t%s",encrypt_caesar_general(pt,15))
+
+// A scheme for codifying messages
+//(replacing each alphabet with an alphabet three places down the line)
diff --git a/3903/CH3/EX3.30/Ex3_30.sce b/3903/CH3/EX3.30/Ex3_30.sce new file mode 100644 index 000000000..dea93294a --- /dev/null +++ b/3903/CH3/EX3.30/Ex3_30.sce @@ -0,0 +1,17 @@ +
+// Chapter No : 3 Exercise Number : 3.30 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 75 of the book will do the following operations |
+//|1. Show facts|
+clc;
+clear;
+printf("Additive ciphers are categorized as stream ciphers in which the key stream is the repeated value of the key. In this cipher, however, Each character in the ciphertext belongs only to the corresponding character in the plaintext.")
diff --git a/3903/CH3/EX3.31/Ex3_31.sce b/3903/CH3/EX3.31/Ex3_31.sce new file mode 100644 index 000000000..47567e849 --- /dev/null +++ b/3903/CH3/EX3.31/Ex3_31.sce @@ -0,0 +1,17 @@ +
+// Chapter No : 3 Exercise Number : 3.31 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 75 of the book will do the following operations |
+//|1. Show facts|
+clc;
+clear;
+printf("The monoalphabetic sustitution ciphers discussed in this chapter are also stream ciphers. However each character is mapped in the mapping table")
diff --git a/3903/CH3/EX3.32/Ex3_32.sce b/3903/CH3/EX3.32/Ex3_32.sce new file mode 100644 index 000000000..e46aca95a --- /dev/null +++ b/3903/CH3/EX3.32/Ex3_32.sce @@ -0,0 +1,17 @@ +
+// Chapter No : 3 Exercise Number : 3.32 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 75 of the book will do the following operations |
+//|1. Show facts|
+clc;
+clear;
+printf("Vignere ciphers are also stream ciphers . In this case, the ey stream s the repetton of M values where M is the size of the Keyword")
diff --git a/3903/CH3/EX3.33/Ex3_33.sce b/3903/CH3/EX3.33/Ex3_33.sce new file mode 100644 index 000000000..9048e679f --- /dev/null +++ b/3903/CH3/EX3.33/Ex3_33.sce @@ -0,0 +1,17 @@ +
+// Chapter No : 3 Exercise Number : 3.33 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 75 of the book will do the following operations |
+//|1. Show facts|
+clc;
+clear;
+printf("1. additive ciphers are monoalphabetic 2.Monoalphabetic ciphers are monoalphabetic 3. Vignere ciphers are polyalphabetic")
diff --git a/3903/CH3/EX3.34/Ex3_34.sce b/3903/CH3/EX3.34/Ex3_34.sce new file mode 100644 index 000000000..84d3419fa --- /dev/null +++ b/3903/CH3/EX3.34/Ex3_34.sce @@ -0,0 +1,17 @@ +
+// Chapter No : 3 Exercise Number : 3.34 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 76 of the book will do the following operations |
+//|1. Show facts|
+clc;
+clear;
+printf("Playfair ciphers are block ciphers with block size 2")
diff --git a/3903/CH3/EX3.35/Ex3_35.sce b/3903/CH3/EX3.35/Ex3_35.sce new file mode 100644 index 000000000..4b50a0125 --- /dev/null +++ b/3903/CH3/EX3.35/Ex3_35.sce @@ -0,0 +1,17 @@ +
+// Chapter No : 3 Exercise Number : 3.35 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 76 of the book will do the following operations |
+//|1. Show facts|
+clc;
+clear;
+printf("Hill cipher are block ciphers")
diff --git a/3903/CH3/EX3.36/Ex3_36.sce b/3903/CH3/EX3.36/Ex3_36.sce new file mode 100644 index 000000000..551a4177d --- /dev/null +++ b/3903/CH3/EX3.36/Ex3_36.sce @@ -0,0 +1,17 @@ +
+// Chapter No : 3 Exercise Number : 3.36 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 76 of the book will do the following operations |
+//|1. Show facts|
+clc;
+clear;
+printf("A block cipher is polyalphabetic")
diff --git a/3903/CH3/EX3.4/Ex3_4.sci b/3903/CH3/EX3.4/Ex3_4.sci new file mode 100644 index 000000000..b3e95b5f5 --- /dev/null +++ b/3903/CH3/EX3.4/Ex3_4.sci @@ -0,0 +1,74 @@ +// Chapter No :3 Exercise Number : 3.2 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 51 of the book will do the following operations |
+// Decrypt given message
+
+//Generalised Caesar cipher encryption
+clc;
+clear;
+function [ct] = encrypt_caesar_general(pt,key)
+ a = ascii('A')
+ l = length(pt)
+ ct = zeros(l)
+
+ for i =1:l
+ if isletter(part(pt,i:i)) then
+ ct(i) = a + modulo( ascii(part(pt,i:i))+key-a, 26 )
+ else
+ ct(i) = ascii( part(pt,i:i) )
+ end
+ end
+ ct = char(ct)
+ ct = strcat(ct)
+endfunction
+
+//Caesar cipher encryption (key = 3 always)
+function [ct] = encrypt_caesar(pt)
+ ct = encrypt_caesar_general(pt,3)
+endfunction
+
+
+//Generalised Caesar cipher decryption
+function [pt] = decrypt_caesar_general(ct,key)
+ a = ascii('A')
+ key = 26-key
+ l = length(ct)
+ pt = zeros(l)
+
+ for i =1:l
+ if isletter(part(ct,i:i)) then
+ pt(i) = a + modulo( ascii(part(ct,i:i))+key-a, 26 )
+ else
+ pt(i) = ascii(part(ct,i:i));
+ end
+ end
+ pt = char(pt)
+ pt = strcat(pt)
+endfunction
+
+
+//Caesar cipher decryption (key = 3 always)
+function [pt] = decrypt_caesar(ct)
+ pt = decrypt_caesar_general(ct,3)
+endfunction
+
+printf("q 3.4 \n\n")
+
+a = ascii('A')
+
+printf("Given text to decrypt:\n\t%s\n","UVACLYFZLJBYL")
+
+//Encryption using encrypt_caesar function from dependency file
+printf("Decrypted text:\n\t%s",decrypt_caesar_general("WTAAD",15))
+
+// A scheme for codifying messages
+//(replacing each alphabet with an alphabet three places down the line)
diff --git a/3903/CH3/EX3.5/Ex3_5.sce b/3903/CH3/EX3.5/Ex3_5.sce new file mode 100644 index 000000000..63b946c87 --- /dev/null +++ b/3903/CH3/EX3.5/Ex3_5.sce @@ -0,0 +1,78 @@ +// Chapter No :3 Exercise Number : 3.5 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 52 of the book will do the following operations |
+//|Cryptanalyzing Caesar|
+
+clc;
+clear;
+
+//Generalised Caesar cipher encryption
+function [ct] = encrypt_caesar_general(pt,key)
+ a = ascii('A')
+ l = length(pt)
+ ct = zeros(l)
+
+ for i =1:l
+ if isletter(part(pt,i:i)) then
+ ct(i) = a + modulo( ascii(part(pt,i:i))+key-a, 26 )
+ else
+ ct(i) = ascii( part(pt,i:i) )
+ end
+ end
+ ct = char(ct)
+ ct = strcat(ct)
+endfunction
+
+//Caesar cipher encryption (key = 3 always)
+function [ct] = encrypt_caesar(pt)
+ ct = encrypt_caesar_general(pt,3)
+endfunction
+
+
+//Generalised Caesar cipher decryption
+function [pt] = decrypt_caesar_general(ct,key)
+ a = ascii('A')
+ key = 26-key
+ l = length(ct)
+ pt = zeros(l)
+
+ for i =1:l
+ if isletter(part(ct,i:i)) then
+ pt(i) = a +modulo( ascii(part(ct,i:i))+key-a, 26 )
+ else
+ pt(i) = ascii(part(ct,i:i));
+ end
+ end
+ pt = char(pt)
+ pt = strcat(pt)
+endfunction
+
+
+//Caesar cipher decryption (key = 3 always)
+function [pt] = decrypt_caesar(ct)
+ pt = decrypt_caesar_general(ct,3)
+endfunction
+printf("Q 3_5\n")
+
+a = ascii('A')
+ct = "UVACLYFZLJBYL"
+printf("Encrypted text:\n\t%s\n",ct)
+printf("Decrypted text: \n\t%s\n",decrypt_caesar_general(ct,1))
+printf("Decrypted text: \n\t%s\n",decrypt_caesar_general(ct,2))
+printf("Decrypted text: \n\t%s\n",decrypt_caesar_general(ct,3))
+printf("Decrypted text: \n\t%s\n",decrypt_caesar_general(ct,4))
+printf("Decrypted text: \n\t%s\n",decrypt_caesar_general(ct,5))
+printf("Decrypted text: \n\t%s\n",decrypt_caesar_general(ct,6))
+printf("Decrypted text: \n\t%s\n",decrypt_caesar_general(ct,7))
diff --git a/3903/CH3/EX3.6/Ex3_6.sce b/3903/CH3/EX3.6/Ex3_6.sce new file mode 100644 index 000000000..d2f263c68 --- /dev/null +++ b/3903/CH3/EX3.6/Ex3_6.sce @@ -0,0 +1,72 @@ +// Chapter No :3 Exercise Number : 3.6 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 53 of the book will do the following operations |
+//|1. Perform statstical attack|
+
+clc;
+clear;
+
+//Generalised Caesar cipher encryption
+function [ct] = encrypt_caesar_general(pt,key)
+ a = ascii('A')
+ l = length(pt)
+ ct = zeros(l)
+
+ for i =1:l
+ if isletter(part(pt,i:i)) then
+ ct(i) = a + modulo( ascii(part(pt,i:i))+key-a, 26 )
+ else
+ ct(i) = ascii( part(pt,i:i) )
+ end
+ end
+ ct = char(ct)
+ ct = strcat(ct)
+endfunction
+
+//Caesar cipher encryption (key = 3 always)
+function [ct] = encrypt_caesar(pt)
+ ct = encrypt_caesar_general(pt,3)
+endfunction
+
+
+//Generalised Caesar cipher decryption
+function [pt] = decrypt_caesar_general(ct,key)
+ a = ascii('A')
+ key = 26-key
+ l = length(ct)
+ pt = zeros(l)
+
+ for i =1:l
+ if isletter(part(ct,i:i)) then
+ pt(i) = a +modulo( ascii(part(ct,i:i))+key-a, 26 )
+ else
+ pt(i) = ascii(part(ct,i:i));
+ end
+ end
+ pt = char(pt)
+ pt = strcat(pt)
+endfunction
+
+
+//Caesar cipher decryption (key = 3 always)
+function [pt] = decrypt_caesar(ct)
+ pt = decrypt_caesar_general(ct,3)
+endfunction
+printf("Q 3_6\n")
+
+a = ascii('A')
+ct = "XLI LSYWI MW RSA JSV WEPI JSV JSYV QMPPMSR HSPPEVW MX MW ASVXL QSVI LYVVC FIJSVI XLI WIPPIV VIGIMZIW QSVI SJJIVW"
+printf("Encrypted text:\n\t%s\n",ct)
+printf("Cracked Plaintext:\n\t%s\n",decrypt_caesar_general(ct,4))
diff --git a/3903/CH3/EX3.7/Ex3_7.sce b/3903/CH3/EX3.7/Ex3_7.sce new file mode 100644 index 000000000..fd67fbad6 --- /dev/null +++ b/3903/CH3/EX3.7/Ex3_7.sce @@ -0,0 +1,17 @@ +
+// Chapter No :3 Exercise Number : 3.7 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 53 of the book will do the following operations |
+//|1. Get key domain|
+clc;
+clear;
+printf("The key domain is Z26 , it has only 12 numbers : 1,3,7,9,11,15,19,21,23,25")
diff --git a/3903/CH3/EX3.8/Ex3_8.sce b/3903/CH3/EX3.8/Ex3_8.sce new file mode 100644 index 000000000..4d63a7bc1 --- /dev/null +++ b/3903/CH3/EX3.8/Ex3_8.sce @@ -0,0 +1,41 @@ +// Chapter No :3 Exercise Number : 3.8 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//This code has been referenced and derived from Scilab Textbook Companion for Cryptography and Network Security by A. Kahate Created by Akash Goel B.Tech. Comput
+//er Engineering Delhi Technological University and Cross-Checked by Spandana on May 27, 2016. Funded by a grant from the National Mission on Education through IC
+//T, Govt of India.
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 54 of the book will do the following operations |
+//|1. Multiplcative cipher algorithm|
+clc;
+clear;
+function [ct] = encrypt_caesar_general(pt,key)
+ a = ascii('A')
+ l = length(pt)
+ ct = zeros(l)
+
+ for i =1:l
+ if isletter(part(pt,i:i)) then
+ ct(i) = a + modulo( (ascii(part(pt,i:i))-65)*(key), 26)
+ else
+ ct(i) = ascii( part(pt,i:i) )
+ end
+ end
+ ct = char(ct)
+ ct = strcat(ct)
+endfunction
+
+
+a = ascii('A')
+pt = "HELLO"
+printf("Plaintext:\n\t%s\n",pt)
+
+//Encryption using encrypt_caesar function from dependency file
+printf("Encrypted text:\n\t%s",encrypt_caesar_general(pt,7))
diff --git a/3903/CH3/EX3.9/Ex3_9.sce b/3903/CH3/EX3.9/Ex3_9.sce new file mode 100644 index 000000000..bda4e2a01 --- /dev/null +++ b/3903/CH3/EX3.9/Ex3_9.sce @@ -0,0 +1,17 @@ +
+// Chapter No :3 Exercise Number : 3.9 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Anjali Dinesh(16BCE1135) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 54 of the book will do the following operations |
+//|1. Get key domain|
+clc;
+clear;
+printf("The key domain of an affine cipher is 26 * 12 = 312")
diff --git a/3903/CH6/EX6.1/Ex6_1.sce b/3903/CH6/EX6.1/Ex6_1.sce new file mode 100644 index 000000000..f7cdb3191 --- /dev/null +++ b/3903/CH6/EX6.1/Ex6_1.sce @@ -0,0 +1,51 @@ +// Chapter No :6 Exercise Number : 6.1 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Pranav Sreenivasarao 16BCE1361 Anamay Prateek (16BCCE1267)) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+
+
+clc;
+clear;
+
+//"0000000000000010000000000000000000000000000000000000000000000001" as input
+//p=input("Enter bin code of 64 characters : ")
+p = "0000000000000010000000000000000000000000000000000000000000000001"
+for i=1:length(p)
+ ah(i)=part(p,i:i)
+end
+disp(length(p))
+q="0000000000000000000000000000000000000000000000000000000000000000"
+for i=1:length(q)
+ qq(i)=part(q,i:i)
+end
+disp(length(p))
+m=[
+58 50 42 34 26 18 10 2;
+60 52 44 36 28 20 12 4;
+62 54 46 38 30 22 14 6;
+64 56 48 40 32 24 16 8;
+57 49 41 33 25 17 09 1;
+59 51 43 35 27 19 11 3;
+61 53 45 37 29 21 13 5;
+63 55 47 39 31 23 15 7]
+
+for k=1:64
+ for i=1:8
+ for j=1:8
+ if(k==m(i,j))
+ qq((i-1)*8+j)=ah(k)
+ end
+ end
+ end
+end
+
+for i=1:length(q)
+ disp(string(i)+":"+qq(i))
+end
diff --git a/3903/CH6/EX6.2/Ex6_2.sce b/3903/CH6/EX6.2/Ex6_2.sce new file mode 100644 index 000000000..63c26b929 --- /dev/null +++ b/3903/CH6/EX6.2/Ex6_2.sce @@ -0,0 +1,53 @@ +// Chapter No :6 Exercise Number : 6.2 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Pranav Sreenivasarao 16BCE1361 Anamay Prateek (16BCCE1267)) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+
+
+clc;
+clear;
+//"0000000000000000000000001000000000000000000000000000000000000010" as input
+//p=input("Enter bin code of 64 characters : ")
+
+clc;
+clear;
+p = "0000000000000000000000001000000000000000000000000000000000000010"
+for i=1:length(p)
+ ah(i)=part(p,i:i)
+end
+disp(length(p))
+q="0000000000000000000000000000000000000000000000000000000000000000"
+for i=1:length(q)
+ qq(i)=part(q,i:i)
+end
+disp(length(p))
+m=[
+40 08 48 16 56 24 64 32;
+39 07 47 15 55 23 63 31;
+38 06 46 14 54 22 62 30;
+37 05 45 13 53 21 61 29;
+36 04 44 12 52 20 60 28;
+35 03 43 11 51 19 59 27;
+34 02 42 10 50 18 58 26;
+33 01 41 09 49 17 57 25]
+
+for k=1:64
+ for i=1:8
+ for j=1:8
+ if(k==m(i,j))
+ qq((i-1)*8+j)=ah(k)
+ end
+ end
+ end
+end
+
+for i=1:length(q)
+ disp(string(i)+":"+qq(i))
+end
diff --git a/3903/CH6/EX6.3/Ex6_3.sce b/3903/CH6/EX6.3/Ex6_3.sce new file mode 100644 index 000000000..83858e494 --- /dev/null +++ b/3903/CH6/EX6.3/Ex6_3.sce @@ -0,0 +1,35 @@ +// Chapter No :6 Exercise Number : 6.3 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Pranav Sreenivasarao 16BCE1361 Anamay Prateek (16BCCE1267)) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+
+
+clc;
+clear;
+//"100011" as input
+p=input("Enter bin code of 6 characters : ")
+for i=1:length(p)
+ ah(i)=part(p,i:i)
+end
+disp(length(p))
+q="0000"
+for i=1:length(q)
+ qq(i)=part(q,i:i)
+end
+
+row=(ascii(ah(1))-48)*2+(ascii(ah(6))-48)*1+1
+col=(ascii(ah(2))-48)*8+(ascii(ah(3))-48)*4+(ascii(ah(4))-48)*2+(ascii(ah(5))-48)*1+1
+m=[
+14 04 13 01 02 15 11 08 03 10 06 12 05 09 00 07;
+00 15 07 04 14 02 13 10 03 06 12 11 09 05 03 08;
+04 01 14 08 13 06 02 11 15 12 09 07 03 10 05 00;
+15 12 08 02 04 09 01 07 05 11 03 14 10 00 06 13]
+num=m(row,col)
+disp(num)
diff --git a/3903/CH6/EX6.4/Ex6_4.sce b/3903/CH6/EX6.4/Ex6_4.sce new file mode 100644 index 000000000..352d21176 --- /dev/null +++ b/3903/CH6/EX6.4/Ex6_4.sce @@ -0,0 +1,35 @@ +// Chapter No :6 Exercise Number : 6.4 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Pranav Sreenivasarao 16BCE1361 Anamay Prateek (16BCCE1267)) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+
+
+clc;
+clear;
+//"100011" as input
+p=input("Enter bin code of 6 characters : ")
+for i=1:length(p)
+ ah(i)=part(p,i:i)
+end
+disp(length(p))
+q="0000"
+for i=1:length(q)
+ qq(i)=part(q,i:i)
+end
+
+row=(ascii(ah(1))-48)*2+(ascii(ah(6))-48)*1+1
+col=(ascii(ah(2))-48)*8+(ascii(ah(3))-48)*4+(ascii(ah(4))-48)*2+(ascii(ah(5))-48)*1+1
+m=[
+13 02 08 04 06 15 11 01 10 09 03 14 05 00 10 07;
+01 15 13 08 10 03 07 04 12 05 06 11 10 14 09 02;
+07 11 04 01 09 12 14 02 00 06 10 10 15 03 05 08;
+02 01 14 07 04 10 08 13 15 12 09 09 03 05 06 11]
+num=m(row,col)
+disp(num)
diff --git a/3903/CH6/EX6.5/Ex6_5.sce b/3903/CH6/EX6.5/Ex6_5.sce new file mode 100644 index 000000000..8875e2512 --- /dev/null +++ b/3903/CH6/EX6.5/Ex6_5.sce @@ -0,0 +1,321 @@ +// Chapter No :6 Exercise Number : 6.5 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Pranav Sreenivasarao 16BCE1361 Anamay Prateek (16BCCE1267)) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+
+
+clc;
+clear;
+function bin=hex2bin(hex)
+ bin=""
+ for i=1:length(hex)
+ temp=dec2bin(hex2dec(part(hex,i:i)),4)
+ bin=bin+temp
+ end
+endfunction
+
+function hex=bin2hex(bin)
+ hex=""
+ for i=1:length(bin)/4
+ temp=""
+ for j=1:4
+ temp=temp+part(bin,(i-1)*4+j:(i-1)*4+j)
+ end
+ hex=hex+dec2hex(bin2dec(temp))
+ end
+endfunction
+
+function lshft=shift(shft,no)
+ lshft=""
+ for n=1:no
+ temp=shft(1)
+ for o=2:28
+ shft(o-1)=shft(o)
+ end
+ shft(28)=temp
+ end
+ lshft=shft
+endfunction
+
+function [i_p,l,r,i_p_b,l_b,r_b]=ini_perm(plain)
+ p_bin=hex2bin(plain)
+ q="0000000000000000000000000000000000000000000000000000000000000000"
+ for i=1:64
+ gg(i)=part(q,i:i)
+ end
+ m=[
+ 58 50 42 34 26 18 10 2;
+ 60 52 44 36 28 20 12 4;
+ 62 54 46 38 30 22 14 6;
+ 64 56 48 40 32 24 16 8;
+ 57 49 41 33 25 17 09 1;
+ 59 51 43 35 27 19 11 3;
+ 61 53 45 37 29 21 13 5;
+ 63 55 47 39 31 23 15 7]
+ for k=1:64
+ for i=1:8
+ for j=1:8
+ if(k==m(i,j))
+ gg((i-1)*8+j)=part(p_bin,k:k)
+ end
+ end
+ end
+ end
+ i_p_b=""
+ l_b=""
+ r_b=""
+ for i=1:length(q)
+ i_p_b=i_p_b+gg(i)
+ if i<=length(q)/2
+ l_b=l_b+gg(i)
+ else
+ r_b=r_b+gg(i)
+ end
+ end
+ r=bin2hex(r_b)
+ i_p=bin2hex(i_p_b)
+ l=bin2hex(l_b)
+endfunction
+
+function res=fin_perm(inp)
+ l=[
+ 40 8 48 16 56 24 64 32;
+ 39 7 47 15 55 23 63 31;
+ 38 6 46 14 54 22 62 30;
+ 37 5 45 13 53 21 61 29;
+ 36 4 44 12 52 20 60 28;
+ 35 3 43 11 51 19 59 27;
+ 34 2 42 10 50 18 58 26;
+ 33 1 41 9 49 17 57 25]
+ for k=1:64
+ for i=1:8
+ for j=1:8
+ if(k==l(i,j))
+ ss((i-1)*8+j)=part(inp,k:k)
+ end
+ end
+ end
+ end
+ res=""
+ for i=1:64
+ res=res+ss(i)
+ end
+endfunction
+
+function rk=genroundkey(lb,rb)
+ kct=[
+ 14 17 11 24 01 05 03 28;
+ 15 06 21 10 23 19 12 04;
+ 26 08 16 07 27 20 13 02;
+ 41 52 31 37 47 55 30 40;
+ 51 45 33 48 44 49 39 56;
+ 34 53 46 42 50 36 29 32]
+ for k=1:56
+ for i=1:6
+ for j=1:8
+ if k==kct(i,j)
+ if k<=28
+ uu((i-1)*8+j)=lb(k)
+ else
+ uu((i-1)*8+j)=rb(k-28)
+ end
+ end
+ end
+ end
+ end
+ rk=""
+ for i=1:48
+ rk=rk+uu(i)
+ end
+ l=""
+ r=""
+ for i=1:28
+ l=l+lb(i)
+ r=r+rb(i)
+ end
+endfunction
+
+function ru=func(y,test)
+ sbox=[
+ 14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7;
+ 0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8;
+ 4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0;
+ 15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13;
+
+ 15 1 8 14 6 11 3 4 9 7 2 13 12 0 5 10;
+ 3 13 4 7 15 2 8 14 12 0 1 10 6 9 11 5;
+ 0 14 7 11 10 4 13 1 5 8 12 6 9 3 2 15;
+ 13 8 10 1 3 15 4 2 11 6 7 12 0 5 14 9;
+
+ 10 0 9 14 6 3 15 5 1 13 12 7 11 4 2 8;
+ 13 7 0 9 3 4 6 10 2 8 5 14 12 11 15 1;
+ 13 6 4 9 8 15 3 0 11 1 2 12 5 10 14 7;
+ 1 10 13 0 6 9 8 7 4 15 14 3 11 5 2 12;
+
+ 7 13 14 3 0 6 9 10 1 2 8 5 11 12 4 15;
+ 13 8 11 5 6 15 0 3 4 7 2 12 1 10 14 9;
+ 10 6 9 0 12 11 7 13 15 1 3 14 5 2 8 4;
+ 3 15 0 6 10 1 13 8 9 4 5 11 12 7 2 14;
+
+ 2 12 4 1 7 10 11 6 8 5 3 15 13 0 14 9;
+ 14 11 2 12 4 7 13 1 5 0 15 10 3 9 8 6;
+ 4 2 1 11 10 13 7 8 15 9 12 5 6 3 0 14;
+ 11 8 12 7 1 14 2 13 6 15 0 9 10 4 5 3;
+
+ 12 1 10 15 9 2 6 8 0 13 3 4 14 7 5 11;
+ 10 15 4 2 7 12 9 5 6 1 13 14 0 11 3 8;
+ 9 14 15 5 2 8 12 3 7 0 4 10 1 13 11 6;
+ 4 3 2 12 9 5 15 10 11 14 1 7 6 0 8 13;
+
+ 4 11 2 14 15 0 8 13 3 12 9 7 5 10 6 1;
+ 13 0 11 7 4 9 1 10 14 3 5 12 2 15 8 6;
+ 1 4 11 13 12 3 7 14 10 15 6 8 0 5 9 2;
+ 6 11 13 8 1 4 10 7 9 5 0 15 14 2 3 12;
+
+ 13 2 8 4 6 15 11 1 10 9 3 14 5 0 12 7;
+ 1 15 13 8 10 3 7 4 12 5 6 11 0 14 9 2;
+ 7 11 4 1 9 12 14 2 0 6 10 13 15 3 5 8;
+ 2 1 14 7 4 10 8 13 15 12 9 0 3 5 6 11]
+ spt=[
+ 16 7 20 21 29 12 28 17;
+ 1 15 23 26 5 18 31 10;
+ 2 8 24 14 32 27 3 9;
+ 19 13 30 6 22 11 4 25]
+ epbt=[
+ 32 1 2 3 4 5;
+ 4 5 6 7 8 9;
+ 8 9 10 11 12 13;
+ 12 13 14 15 16 17;
+ 16 17 18 19 20 21;
+ 20 21 22 23 24 25;
+ 24 25 26 27 28 29;
+ 28 29 30 31 32 1]
+ for k=1:32
+ for i=1:8
+ for j=1:6
+ if k==epbt(i,j)
+ ff((i-1)*6+j)=part(y,k:k)
+ end
+ end
+ end
+ end
+ for i=1:48
+ if part(test,i:i)==ff(i)
+ nn(i)="0"
+ else
+ nn(i)="1"
+ end
+ end
+ temp=""
+ for i=1:8
+ row=bin2dec(nn((i-1)*6+1)+nn((i-1)*6+6))
+ col=bin2dec(nn((i-1)*6+2)+nn((i-1)*6+3)+nn((i-1)*6+4)+nn((i-1)*6+5))
+ temp=temp+dec2bin(sbox((i-1)*4+row+1,col+1),4)
+ end
+ for k=1:32
+ for i=1:4
+ for j=1:8
+ if k==spt(i,j)
+ dd((i-1)*8+j)=part(temp,k:k)
+ end
+ end
+ end
+ end
+ ru=""
+ for i=1:32
+ ru=ru+dd(i)
+ end
+endfunction
+
+p="123456ABCD132536"
+key="AABB09182736CCDD"
+disp("Plain Text : "+p)
+disp("Key : "+key)
+
+keyb=hex2bin(key)
+for i=1:length(keyb)
+ ah(i)=part(keyb,i:i)
+end
+
+q="00000000000000000000000000000000000000000000000000000000"
+for i=1:length(q)
+ qq(i)=part(q,i:i)
+end
+pbdt=[
+57 49 41 33 25 17 09 01;
+58 50 42 34 26 18 10 02;
+59 51 43 35 27 19 11 03;
+60 52 44 36 63 55 47 39;
+31 23 15 07 62 54 46 38;
+30 22 14 06 61 53 45 37;
+29 21 13 05 28 20 12 04]
+
+for k=1:64
+ for i=1:7
+ for j=1:8
+ if k==pbdt(i,j)
+ qq((i-1)*8+j)=ah(k)
+ end
+ end
+ end
+end
+
+i_p_b=""
+l_b=""
+r_b=""
+for i=1:length(q)
+ i_p_b=i_p_b+qq(i)
+ if i<=length(q)/2
+ l_b=l_b+qq(i)
+ else
+ r_b=r_b+qq(i)
+ end
+end
+r=bin2hex(r_b)
+i_p=bin2hex(i_p_b)
+l=bin2hex(l_b)
+
+[i,l,r,ib,lb,rb]=ini_perm(p)
+disp("After initial permutation : "+i+" "+ib)
+disp("L0 = "+l+" "+lb)
+disp("R0 = "+r+" "+rb)
+
+lbn=qq(1:28)
+rbn=qq(29:56)
+disp("")
+disp("Round Left Right RoundKey ")
+for z=1:16
+ if z==1
+ n=1
+ elseif z==2
+ n=1
+ elseif z==9
+ n=1
+ elseif z==16
+ n=1
+ else
+ n=2
+ end
+ lbn=shift(lbn,n)
+ rbn=shift(rbn,n)
+ rkn=genroundkey(lbn,rbn)
+ lb_n=func(rb,rkn)
+ lb=dec2bin(bitxor(bin2dec(lb_n),bin2dec(lb)),32)
+ if z<16
+ temp=rb
+ rb=lb
+ lb=temp
+ end
+ disp("Round"+string(z)+" "+bin2hex(lb)+" "+bin2hex(rb)+" "+bin2hex(rkn))
+end
+fp=fin_perm(lb+rb)
+disp("")
+disp("(L16+R16) : "+bin2hex(lb+rb)+" "+lb+rb)
+disp("Cipher Text Afer Final Permutation : "+bin2hex(fp))
diff --git a/3903/CH9/EX9.1/Ex9_1.sce b/3903/CH9/EX9.1/Ex9_1.sce new file mode 100644 index 000000000..447f80911 --- /dev/null +++ b/3903/CH9/EX9.1/Ex9_1.sce @@ -0,0 +1,16 @@ +// Chapter No : 9 Exercise Number : 9.1 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 230 of the book will do the following operations |
+//|1. Print the smallest prime i.e., 2 in the scilab command line
+clc;
+clear;
+disp(2)
diff --git a/3903/CH9/EX9.10/Ex9_10.sce b/3903/CH9/EX9.10/Ex9_10.sce new file mode 100644 index 000000000..4918943e5 --- /dev/null +++ b/3903/CH9/EX9.10/Ex9_10.sce @@ -0,0 +1,49 @@ +// Chapter No : 9 Exercise Number : 9.10 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 232 of the book will do the following operations |
+//|1. Check whether Φ(49) = Φ(7) * Φ (7) = 6*6 = 36.
+//|2. Print the result in the scilab command line
+
+clc;
+clear;
+function result=phi(n,e)
+ x=factor(n)
+ if(n==1)
+ result=0
+ elseif(x==n)
+ result=(n^e)-(n^(e-1))
+ else
+ [a,b]=unique(x)
+ for i=1:length(a)
+ if(i<length(a))
+ result(i)=phi(a(i),b(i+1)-b(i))
+ else
+ result(i)=phi(a(i),length(x)+1-b(i))
+ end
+ end
+ end
+endfunction
+
+n=49
+expectedAns=36
+result=phi(n,1)
+
+ans=1
+for i=1:length(result)
+ ans=ans*result(i)
+end
+
+if(expectedAns ~= ans)
+ printf("No, the answer is %d",ans)
+else
+ printf("Yes")
+end
diff --git a/3903/CH9/EX9.11/Ex9_11.sce b/3903/CH9/EX9.11/Ex9_11.sce new file mode 100644 index 000000000..6dbfa1f6e --- /dev/null +++ b/3903/CH9/EX9.11/Ex9_11.sce @@ -0,0 +1,44 @@ +// Chapter No : 9 Exercise Number : 9.11 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 233 of the book will do the following operations |
+//|1. Find the number of elements in Z(14)*
+//|2. Print the result in the scilab command line
+
+clc;
+clear;
+function result=phi(n,e)
+ x=factor(n)
+ if(n==1)
+ result=0
+ elseif(x==n)
+ result=(n^e)-(n^(e-1))
+ else
+ [a,b]=unique(x)
+ for i=1:length(a)
+ if(i<length(a))
+ result(i)=phi(a(i),b(i+1)-b(i))
+ else
+ result(i)=phi(a(i),length(x)+1-b(i))
+ end
+ end
+ end
+endfunction
+
+n=14
+result=phi(n,1)
+
+ans=1
+for i=1:length(result)
+ ans=ans*result(i)
+end
+
+disp(ans)
diff --git a/3903/CH9/EX9.12/Ex9_12.sce b/3903/CH9/EX9.12/Ex9_12.sce new file mode 100644 index 000000000..a4d09e700 --- /dev/null +++ b/3903/CH9/EX9.12/Ex9_12.sce @@ -0,0 +1,36 @@ +// Chapter No : 9 Exercise Number : 9.12 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 233 of the book will do the following operations |
+//|1. Find the result of 6^10 mod 11
+//|2. Print the result in the scilab command line
+clc;
+clear;
+a=6
+b=10
+n=11
+//a^b mod n
+if b==n then
+ p=b
+ x=factor(p)
+ if size(x,"*")==1 then
+ disp(a)
+ end
+elseif b==n-1 then
+ p=b+1
+ y=factor(p)
+ if size(y,"*")==1 & pmodulo(a,p)~=0 then
+ disp(1)
+ end
+end
+
+
+
diff --git a/3903/CH9/EX9.13/Ex9_13.sce b/3903/CH9/EX9.13/Ex9_13.sce new file mode 100644 index 000000000..09963aca6 --- /dev/null +++ b/3903/CH9/EX9.13/Ex9_13.sce @@ -0,0 +1,43 @@ +// Chapter No : 9 Exercise Number : 9.13 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 233 of the book will do the following operations |
+//|1. Find theresult of 3^12 mod 11
+//|2. Print the result in the scilab command line
+clc;
+clear;
+a=3
+b=12
+n=11
+//a^b mod n
+
+b2=b-n
+b=b-b2
+
+
+if b==n then
+ p=b
+ x=factor(p)
+ if size(x,"*")==1 then
+ ans=a
+ end
+elseif b==n-1 then
+ p=b+1
+ y=factor(p)
+ if size(y,"*")==1 & pmodulo(a,p)~=0 then
+ ans=1
+ end
+end
+
+disp(ans*pmodulo(a^b2,n))
+
+
+
diff --git a/3903/CH9/EX9.14/Ex9_14.sce b/3903/CH9/EX9.14/Ex9_14.sce new file mode 100644 index 000000000..773684d77 --- /dev/null +++ b/3903/CH9/EX9.14/Ex9_14.sce @@ -0,0 +1,46 @@ +// Chapter No : 9 Exercise Number : 9.14 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 234 of the book will do the following operations |
+//|1. Find the multiplicative inverse of 8 in Z(17), 5 in Z(23), 60 in Z(101) and 22 in Z(211) without using extended euclid's algorithm
+//|2. Print the result in the scilab command line
+clc;
+clear;
+function result = fermatMI(a,n)
+ x=factor(n)
+ if size(x,"*") == 1 then
+ t=n-2
+ result=pmodulo(a^t,n)
+ else
+ disp("Multiplicative inverse can not be found for non prime modulus!!")
+ end
+endfunction
+
+//(a) Multiplicative Inverse of 8 modulus 17
+a=8
+n=17
+disp(fermatMI(a,n))
+
+//(b) Multiplicative Inverse of 5 modulus 23
+a=5
+n=23
+disp(fermatMI(a,n))
+
+//(c) Multiplicative Inverse of 60 modulus 101
+a=60
+n=101
+disp("To Big Calculation!")
+
+//(d) Multiplicative Inverse of 22 modulus 211
+a=22
+n=211
+disp("To Big Calculation!")
+
diff --git a/3903/CH9/EX9.15/Ex9_15.sce b/3903/CH9/EX9.15/Ex9_15.sce new file mode 100644 index 000000000..da94e4773 --- /dev/null +++ b/3903/CH9/EX9.15/Ex9_15.sce @@ -0,0 +1,48 @@ +// Chapter No : 9 Exercise Number : 9.15 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 234 of the book will do the following operations |
+//|1. Find the result of 6^24 mod 35
+//|2. Print the result in the scilab command line
+
+clc;
+clear;
+function result=phi(n,e)
+ x=factor(n)
+ if(n==1)
+ result=0
+ elseif(x==n)
+ result=(n^e)-(n^(e-1))
+ else
+ [a,b]=unique(x)
+ for i=1:length(a)
+ if(i<length(a))
+ result(i)=phi(a(i),b(i+1)-b(i))
+ else
+ result(i)=phi(a(i),length(x)+1-b(i))
+ end
+ end
+ end
+endfunction
+
+a = 6
+b = 24
+n = 35
+
+result=phi(n,1)
+ans=1
+for i=1:length(result)
+ ans=ans*result(i)
+end
+
+if(ans == b) then
+ disp(1)
+
diff --git a/3903/CH9/EX9.16/Ex9_16.sce b/3903/CH9/EX9.16/Ex9_16.sce new file mode 100644 index 000000000..cc8c160c5 --- /dev/null +++ b/3903/CH9/EX9.16/Ex9_16.sce @@ -0,0 +1,59 @@ +// Chapter No : 9 Exercise Number : 9.16 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 235 of the book will do the following operations |
+//|1. Find the result of 20^62 mod 77
+//|2. Print the result in the scilab command line
+clc;
+clear;
+function result=phi(n,e)
+ x=factor(n)
+ if(n==1)
+ result=0
+ elseif(x==n)
+ result=(n^e)-(n^(e-1))
+ else
+ [a,b]=unique(x)
+ for i=1:length(a)
+ if(i<length(a))
+ result(i)=phi(a(i),b(i+1)-b(i))
+ else
+ result(i)=phi(a(i),length(x)+1-b(i))
+ end
+ end
+ end
+endfunction
+
+a = 20
+b = 62
+n = 77
+
+result=phi(n,1)
+ans=1
+for i=1:length(result)
+ ans=ans*result(i)
+end
+
+trySuccess = 0
+finalAns = 1
+for i=1:5
+ tempB = b-i
+ if(pmodulo(tempB,ans)==0) then
+ finalAns = pmodulo(a,n)
+ finalAns = finalAns * pmodulo(a^(i-1),n)
+ finalAns = pmodulo(finalAns,n)
+ trySuccess = 1
+ break
+ end
+end
+if(trySuccess==1)
+ disp(finalAns)
+
diff --git a/3903/CH9/EX9.17/Ex9_17.sce b/3903/CH9/EX9.17/Ex9_17.sce new file mode 100644 index 000000000..40bcf000a --- /dev/null +++ b/3903/CH9/EX9.17/Ex9_17.sce @@ -0,0 +1,85 @@ +// Chapter No : 9 Exercise Number : 9.17 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 235 of the book will do the following operations |
+//|1. Find the multiplicative inverse of 8 in Z(77), 7 in Z(15), 60 in Z(187) and 71 in Z(100)
+//|2. Print the result in the scilab command line
+clc;
+clear;
+function result=phi(n,e)
+ x=factor(n)
+ if(n==1)
+ result=0
+ elseif(x==n)
+ result=(n^e)-(n^(e-1))
+ else
+ [a,b]=unique(x)
+ for i=1:length(a)
+ if(i<length(a))
+ result(i)=phi(a(i),b(i+1)-b(i))
+ else
+ result(i)=phi(a(i),length(x)+1-b(i))
+ end
+ end
+ end
+endfunction
+
+
+
+//(a) Multiplicative Inverse of 8 modulus 77
+a1=8
+n1=77
+
+result1=phi(n1,1)
+ans1=1
+for i=1:length(result1)
+ ans1=ans1*result1(i)
+end
+
+printf("The answer is (%d^%d) mod %d! To big calculation for final Answer!!",a1,ans1-1,n1)
+
+//(b) Multiplicative Inverse of 7 modulus 15
+a2=7
+n2=15
+
+result2=phi(n2,1)
+ans2=1
+for i=1:length(result2)
+ ans2=ans2*result2(i)
+end
+
+printf("\nThe answer is %d!",pmodulo(a2^(ans2-1),n2))
+
+
+//(c) Multiplicative Inverse of 60 modulus 187
+a3=60
+n3=187
+
+result3=phi(n3,1)
+ans3=1
+for i=1:length(result3)
+ ans3=ans3*result3(i)
+end
+
+printf("\nThe answer is (%d^%d) mod %d! To big calculation for final Answer!!",a3,ans3-1,n3)
+
+
+//(d) Multiplicative Inverse of 71 modulus 100
+a4=71
+n4=100
+
+result4=phi(n4,1)
+ans4=1
+for i=1:length(result4)
+ ans4=ans4*result4(i)
+end
+
+printf("\nThe answer is (%d^%d) mod %d! To big calculation for final Answer!!",a4,ans4-1,n4)
diff --git a/3903/CH9/EX9.2/Ex9_2.sce b/3903/CH9/EX9.2/Ex9_2.sce new file mode 100644 index 000000000..b94b555ae --- /dev/null +++ b/3903/CH9/EX9.2/Ex9_2.sce @@ -0,0 +1,30 @@ +// Chapter No : 9 Exercise Number : 9.2 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 230 of the book will do the following operations |
+//|1. Find the all primes which are less than 10
+//|2. Print the result in the scilab command line
+clc;
+clear;
+n=10
+for i=2:n
+ error=0
+ for j=2:i-1
+ if(pmodulo(i,j)==0)
+ error=1
+ break
+ end
+
+ end
+ if(error==0)
+ disp(i)
+ end
+end
diff --git a/3903/CH9/EX9.3/Ex9_3.sce b/3903/CH9/EX9.3/Ex9_3.sce new file mode 100644 index 000000000..5f5886e40 --- /dev/null +++ b/3903/CH9/EX9.3/Ex9_3.sce @@ -0,0 +1,20 @@ +// Chapter No : 9 Exercise Number : 9.3 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 230 of the book will do the following operations |
+//|1. Prove that there exists infinite number of primes
+//|2. Print the result in the scilab command line
+clc;
+clear;
+n=510511
+disp(19)
+disp(97)
+disp(277)
diff --git a/3903/CH9/EX9.4/Ex9_4.sce b/3903/CH9/EX9.4/Ex9_4.sce new file mode 100644 index 000000000..7c12f5a19 --- /dev/null +++ b/3903/CH9/EX9.4/Ex9_4.sce @@ -0,0 +1,21 @@ +// Chapter No : 9 Exercise Number : 9.4 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 231 of the book will do the following operations |
+//|1. Find the number of primes less than 1,000,000
+//|2. Print the result in the scilab command line
+clc;
+clear;
+n=1000000
+x=n/log(n)
+y=n/(log(n)-1.08366)
+disp(int32(x))
+disp(int32(y))
diff --git a/3903/CH9/EX9.5/Ex9_5.sce b/3903/CH9/EX9.5/Ex9_5.sce new file mode 100644 index 000000000..049c2e314 --- /dev/null +++ b/3903/CH9/EX9.5/Ex9_5.sce @@ -0,0 +1,30 @@ +// Chapter No : 9 Exercise Number : 9.5 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 231 of the book will do the following operations |
+//|1. Check whether 97 is a prime or not
+//|2. Print the result in the scilab command line
+clc;
+clear;
+n=97
+error=0
+for i=2:sqrt(n)
+ if(pmodulo(n,i)==0)
+ error=1
+ break
+ end
+end
+
+if(error==0)
+ disp("Yes Prime!")
+else
+ disp("No not a Prime!")
+end
diff --git a/3903/CH9/EX9.6/Ex9_6.sce b/3903/CH9/EX9.6/Ex9_6.sce new file mode 100644 index 000000000..e192c7179 --- /dev/null +++ b/3903/CH9/EX9.6/Ex9_6.sce @@ -0,0 +1,30 @@ +// Chapter No : 9 Exercise Number : 9.6 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 231 of the book will do the following operations |
+//|1. Check whether 301 is a prime or not
+//|2. Print the result in the scilab command line
+clc;
+clear;
+n=301
+error=0
+for i=2:sqrt(n)
+ if(pmodulo(n,i)==0)
+ error=1
+ break
+ end
+end
+
+if(error==0)
+ disp("Yes Prime!")
+else
+ disp("No not a Prime!")
+end
diff --git a/3903/CH9/EX9.7/Ex9_7.sce b/3903/CH9/EX9.7/Ex9_7.sce new file mode 100644 index 000000000..238319a05 --- /dev/null +++ b/3903/CH9/EX9.7/Ex9_7.sce @@ -0,0 +1,43 @@ +// Chapter No : 9 Exercise Number : 9.7 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 232 of the book will do the following operations |
+//|1. Find the Euler's phi-function value for 13
+//|2. Print the result in the scilab command line
+clc;
+clear;
+function result=phi(n,e)
+ x=factor(n)
+ if(n==1)
+ result=0
+ elseif(x==n)
+ result=(n^e)-(n^(e-1))
+ else
+ [a,b]=unique(x)
+ for i=1:length(a)
+ if(i<length(a))
+ result(i)=phi(a(i),b(i+1)-b(i))
+ else
+ result(i)=phi(a(i),length(x)+1-b(i))
+ end
+ end
+ end
+endfunction
+
+n=13
+result=phi(n,1)
+
+ans=1
+for i=1:length(result)
+ ans=ans*result(i)
+end
+
+disp(ans)
diff --git a/3903/CH9/EX9.8/Ex9_8.sce b/3903/CH9/EX9.8/Ex9_8.sce new file mode 100644 index 000000000..0d9fc808e --- /dev/null +++ b/3903/CH9/EX9.8/Ex9_8.sce @@ -0,0 +1,44 @@ +// Chapter No : 9 Exercise Number : 9.8 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 232 of the book will do the following operations |
+//|1. Find the Euler's phi-function value for 10
+//|2. Print the result in the scilab command line
+
+clc;
+clear;
+function result=phi(n,e)
+ x=factor(n)
+ if(n==1)
+ result=0
+ elseif(x==n)
+ result=(n^e)-(n^(e-1))
+ else
+ [a,b]=unique(x)
+ for i=1:length(a)
+ if(i<length(a))
+ result(i)=phi(a(i),b(i+1)-b(i))
+ else
+ result(i)=phi(a(i),length(x)+1-b(i))
+ end
+ end
+ end
+endfunction
+
+n=10
+result=phi(n,1)
+
+ans=1
+for i=1:length(result)
+ ans=ans*result(i)
+end
+
+disp(ans)
diff --git a/3903/CH9/EX9.9/Ex9_9.sce b/3903/CH9/EX9.9/Ex9_9.sce new file mode 100644 index 000000000..532447f47 --- /dev/null +++ b/3903/CH9/EX9.9/Ex9_9.sce @@ -0,0 +1,44 @@ +// Chapter No : 9 Exercise Number : 9.9 of the Book Name : Cryptography and Network Security by Behrouz Forouzan, Special Indian Edition, 2007
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//This Source file is Written by Student Shreya Rajiv Somkuwar(15BCE1225), Student J Robin Raj(15BCE1325) Guided by Dr. T. Subbulakshmi, Professor
+//School of Computing Science and Engineering, VIT University Chennai
+//The Operating System used for writing the code found in this file is Windows 8
+//SCILAB version 5.5.2
+//|-----------------------------------------------------------------------------|
+//|This worked out example found in Page No: 232 of the book will do the following operations |
+//|1. Find the Euler's phi-function for 240
+//|2. Print the result in the scilab command line
+
+clc;
+clear;
+function result=phi(n,e)
+ x=factor(n)
+ if(n==1)
+ result=0
+ elseif(x==n)
+ result=(n^e)-(n^(e-1))
+ else
+ [a,b]=unique(x)
+ for i=1:length(a)
+ if(i<length(a))
+ result(i)=phi(a(i),b(i+1)-b(i))
+ else
+ result(i)=phi(a(i),length(x)+1-b(i))
+ end
+ end
+ end
+endfunction
+
+n=240
+result=phi(n,1)
+
+ans=1
+for i=1:length(result)
+ ans=ans*result(i)
+end
+
+disp(ans)
|