De"ar#me$# O% C&m"u#er E$'i$eeri$' LA( MANUAL Sem) *II (ra$+,) CE SYSTEM SECURITY LIST OF E-.ERIMENTS 1. Write a program to implement Extended Euclidian Algorithm. 2. Write a program to implement Caesar Cipher algorithm. 3. Write a program to implement Vigenre Cipher algorithm. 4. Write a program to implement RSA algorithm. . Write a program to implement !napsac! cr"ptoanal"sis. #. Write a program to implement $i%%ie &ellman !e" exchange algorithm. '. Write a program to generate digital signature using RSA. (. Write a program to implement )u%%er *+er%lo, Attac!. 9. -o stud" Stegnograph" ." storing a secret !e" in a /0E1 image. Department of Computer Engineering, SIES GST Page 1 E-.ERIMENT NO/ 0 E-TENDED EUCLIDIAN ALGORITHM AIM ) - Write a program to implement Extended Euclidian Algorithm. THEORY)- -he e1#e$2e2 Eu+li2ea$ al'&ri#,m is an extension to the Euclidean algorithm. )esides %inding the greatest common di+isor o% integers a and b2 as the Euclidean algorithm does2 it also %inds integers x and y 3one o% ,hich is t"picall" negati+e4 that satis%" )56out7s identit" Extended Euclidian algorithm is used %or8 Sol+ing ax mod n 9 1 Sol+ing ax mod n 9 b 1i+en positi+e integers a and b2 %ind their greatest common di+isor Steps8 : ;% x is the greatest common di+isor o% a and b2 then x di+ides r 9 a < b Reduces pro.lem to %inding largest x that di+ides r and b ;terate CONCLUSIO=8- -he extended Euclidean algorithm is particularl" use%ul ,hen a and b are coprime2 since x is the multiplicati+e in+erse o% a modulo b2 and y is the multiplicati+e in+erse o% b modulo a. Department of Computer Engineering, SIES GST Page 2 E-.ERIMENT NO/ 3 CAESAR CI.HER ALGORITHM AIM ) - Write a program to implement Caesar Cipher algorithm. THEORY)- ;n cr"ptograph"2 a Caesar cipher2 also !no,n as Caesar7s cipher2 the shi%t cipher2 Caesar7s code or Caesar shi%t2 is one o% the simplest and most ,idel" !no,n encr"ption techni>ues. ;t is a t"pe o% su.stitution cipher in ,hich each letter in the plaintext is replaced ." a letter some %ixed num.er o% positions do,n the alpha.et. ?or example2 ,ith a shi%t o% 32 A ,ould .e replaced ." $2 ) ,ould .ecome E2 and so on. -he method is named a%ter /ulius Caesar2 ,ho used it in his pri+ate correspondence. -he encr"ption step per%ormed ." a Caesar cipher is o%ten incorporated as part o% more complex schemes. -he trans%ormation can .e represented ." aligning t,o alpha.ets@ the cipher alpha.et is the plain alpha.et rotated le%t or right ." some num.er o% positions. ?or instance2 here is a Caesar cipher using a le%t rotation o% three places 3the shi%t parameter2 here 32 is used as the !e"48 0lain8 A)C$E?1&;/ABC=*0DRS-EVWFGH Cipher8 $E?1&;/ABC=*0DRS-EVWFGHA)C When encr"pting2 a person loo!s up each letter o% the message in the IplainI line and ,rites do,n the corresponding letter in the IcipherI line. $eciphering is done in re+erse. Ciphertext8 WA& -FB?= EERHD ;RA CF0SV RG&E WA& *$C) 1R/ 0laintext8 the >uic! .ro,n %ox Jumps o+er the la6" dog -he encr"ption can also .e represented using modular arithmetic ." %irst trans%orming the letters into num.ers2 according to the scheme2 A 9 K2 ) 9 12...2 H 9 2.Encr"ption o% a letter ." a shi%t n can .e descri.ed mathematicall" as2 $ecr"ption is per%ormed similarl"2 Department of Computer Engineering, SIES GST Page 3 CONCLUSIO=8- Caesar Cipher is eas" to use .ut it has simple structure and it is eas" to .rea! encr"pted message. Department of Computer Engineering, SIES GST Page 4 E-.ERIMENT NO/ 4 *IGEN5RE CI.HER ALGORITHM AIM ) - Write a program to implement Vigenre Cipher algorithm. THEORY)- -he *i'e$6re +i",er is a method o% encr"pting alpha.etic text ." using a series o% di%%erent Caesar ciphers .ased on the letters o% a !e",ord. ;t is a simple %orm o% pol"alpha.etic su.stitution. Algorithm 1. use Vigenre -a.leau32#L2# matrix4 2. lo,8 letter 3. column8 !e"3suppose !e" length is #2 i.e. !e" 9 3!12 M !#44 Encr"ption N cJ 9 3pJ2 !i4 ,here J Li mod # $ecr"ption N pJ 9x s.t. cJ 9 3x2 !i4 ,here JLi mod # -a.le 8: Department of Computer Engineering, SIES GST Page 5 N Example 7e8 Julie tJuli etJul ... .lai$#e1# )E-S* ?-W&A -B;1& ... Ci",er#e1# !oeas "c>si ... ! 9 3)2 J42 o 9 3E2 u42 e 9 3-2 l42 M N Bong !e",ords can .e used2 .ut a !e",ord o% length three usuall" su%%ices s to smooth out the distri.ution. CONCLUSIO=8- Vigenre cipher is periodic .ecause plain text characters are enciphered one <.":one and adJacent characters are enciphered ,ith a di%%erent part o% the !e". Department of Computer Engineering, SIES GST Page 6 E-.ERIMENT NO/ 4 RSA ALGORITHM AIM ) - Write a program to implement RSA algorithm. THEORY)- RSA is an algorithm %or pu.lic:!e" cr"ptograph" that is .ased on the presumed di%%icult" o% %actoring large integers2 the %actoring pro.lem. RSA stands %or Ron Ri+est2 Adi Shamir and Beonard Adleman2 ,ho %irst pu.licl" descri.ed it in 1O''. A user o% RSA creates and then pu.lishes the product o% t,o large prime num.ers2 along ,ith an auxiliar" +alue2 as their pu.lic !e". -he prime %actors must .e !ept secret. An"one can use the pu.lic !e" to encr"pt a message2 .ut ,ith currentl" pu.lished methods2 i% the pu.lic !e" is large enough2 onl" someone ,ith !no,ledge o% the prime %actors can %easi.l" decode the message. -he RSA algorithm in+ol+es three steps8 !e" generation2 encr"ption and decr"ption. 7e8 'e$era#i&$ RSA in+ol+es a "ubli+ 9e8 and a "riva#e 9e8/ -he pu.lic !e" can .e !no,n to e+er"one and is used %or encr"pting messages. Cessages encr"pted ,ith the pu.lic !e" can onl" .e decr"pted using the pri+ate !e". -he !e"s %or the RSA algorithm are generated the %ollo,ing ,a"8 Choose t,o distinct prime num.ers p and q. : ?or securit" purposes2 the integers p and q should .e chosen at random2 and should .e o% similar .it:length. 0rime integers can .e e%%icientl" %ound using a primalit" test. Compute n 9 pq. : n is used as the modulus %or .oth the pu.lic and pri+ate !e"s Compute P3n4 9 3p<143q<142 ,here P is Euler7s totient %unction. Choose an integer e such that 1 Q e Q P3n4 and greatest common di+isor o% 3e2 P3n44 9 1@ i.e.2 e and P3n4 are coprime. e is released as the pu.lic !e" exponent. Department of Computer Engineering, SIES GST Page 7 e ha+ing a short .it:length and small &amming ,eight results in more e%%icient encr"ption : most commonl" Kx1KKK1 9 #23'. &o,e+er2 small +alues o% e 3such as 34 ha+e .een sho,n to .e less secure in some settings. $etermine d as8 i.e.2 d is the multiplicati+e in+erse o% e mod P3n4. : -his is more clearl" stated as sol+e %or d gi+en 3de4 mod P3n4 9 1. -his is o%ten computed using the extended Euclidean algorithm. d is !ept as the pri+ate !e" exponent. so2 dLe9 1 mod P3n4 -he "ubli+ 9e8 consists o% the modulus n and the pu.lic 3or encr"ption4 exponent e. -he "riva#e 9e8 consists o% the modulus n and the pri+ate 3or decr"ption4 exponent d ,hich must .e !ept secret. 3p2 q2 and P3n4 must also .e !ept secret .ecause the" can .e used to calculate d.4 E$+r8"#i&$ Alice transmits her pu.lic !e" to )o. and !eeps the pri+ate !e" secret. )o. then ,ishes to send message M to Alice. &e %irst turns M into an integer m2 such that ." using an agreed:upon re+ersi.le protocol !no,n as a padding scheme. &e then computes the ciphertext corresponding to . -his can .e done >uic!l" using the method o% exponentiation ." s>uaring. )o. then transmits to Alice. =ote that at least nine +alues o% m could "ield a ciphertext c e>ual to m2.ut this is +er" unli!el" to occur in practice. De+r8"#i&$ Alice can reco+er %rom ." using her pri+ate !e" exponent +ia computing . 1i+en 2 she can reco+er the original message M ." re+ersing the padding scheme. CONCLUSIO= )- Department of Computer Engineering, SIES GST Page RSA7s .iggest ad+antage is that it uses 0u.lic Ae" encr"ption. -his means that text ,ill .e encr"pted ,ith someone7s 0u.lic Ae" 3,hich e+er"one !no,s a.out4. &o,e+er2 onl" the person it is intended %or can read it2 ." using their pri+ate !e" 3,hich onl" the" !no, a.out4. Attempting to use the 0u.lic Ae" to decr"pt the message ,ould not ,or!. RSA can also .e used to IsignI a message2 meaning that the recipient can +eri%" that it ,as sent ." the authenticated user. Department of Computer Engineering, SIES GST Page 9 E-.ERIMENT NO/ : 7NA.SAC7 CRY.TOANALYSIS AIM ) - Write a program to implement !napsac! cr"ptoanal"sis. THEORY)- -he Cer!le:&ellman s"stem is .ased on the su.set sum pro.lem 3a special case o% the !napsac! pro.lem4. -he pro.lem is as %ollo,s8 gi+en a set o% num.ers A and a num.er b2 %ind a su.set o% A2 ,hich sums to .. ;n general2 this pro.lem is !no,n to .e =0:complete. &o,e+er2 i% the set o% num.ers 3called the !napsac!4 is super increasing the pro.lem is 7eas"7 and sol+a.le in pol"nomial time ,ith a simple greed" algorithm. 7e8 'e$era#i&$ -o encr"pt n:.it messages2 choose a super increasing se>uence w 9 3w12 w22 ...2 wn4 o% n non6ero natural num.ers. 0ic! a random integer q2 such that 2 and a random integer2 r2 such that gcd3r2q4 9 1 3i.e. r and q are coprime4. q is chosen this ,a" to ensure the uni>ueness o% the ciphertext. ;% it is an" smaller2 more than one plaintext ma" encr"pt to the same ciphertext. r must .e coprime to q or else it ,ill not ha+e an in+erse mod q. -he existence o% the in+erse o% r is necessar" so that decr"ption is possi.le. =o, calculate the se>uence R 9 3R12 R22 ...2 Rn4 Department of Computer Engineering, SIES GST Page 1! ,here Ri 9 rwi mod q. -he pu.lic !e" is R2 ,hile the pri+ate !e" is 3w2 q2 r4. E$+r8"#i&$ -o encr"pt an n:.it message S 9 3S12 S22 ...2 Sn42 ,here is the i:th .it o% the message and TK2 1U2 calculate -he cr"ptogram then is c. De+r8"#i&$ ;n order to decr"pt a ciphertext c a recei+er has to %ind the message .its Si such that the" satis%" -his ,ould .e a hard pro.lem i% the Ri ,ere random +alues .ecause the recei+er ,ould ha+e to sol+e an instance o% the su.set sum pro.lem2 ,hich is !no,n to .e =0:hard. &o,e+er2 the +alues Ri ,ere chosen such that decr"ption is eas" i% the pri+ate !e" 3w2 q2 r4 is !no,n. -he !e" to decr"ption is to %ind an integer s that is the modular in+erse o% r modulo q. -hat means s satis%ies the e>uation s r mod q 9 1 or e>ui+alentl" there exist an integer k such that sr 9 kq V 1. Since r ,as chosen such that gcd3r2q491 it is possi.le to %ind s and k ." using the Extended Euclidean algorithm. =ext the recei+er o% the ciphertext c computes Department of Computer Engineering, SIES GST Page 11 &ence )ecause o% rs mod > 9 1 and Ri 9 rwi mod q %ollo,s &ence -he sum o% all +alues wi is smaller than q and hence is also in the inter+al WK2q:1X. -hus the recei+er has to sol+e the su.set sum pro.lem -his pro.lem is eas" .ecause w is a superincreasing se>uence. -a!e the largest element in w2 sa" wk. ;% wk Y c' 2 then Sk 9 K2 i% wkZc' 2 then Sk 9 1. -hen2 su.tract wk[Sk %rom c' 2 and repeat these steps until "ou ha+e %igured out S. CONCLUSIO=8- Anapsac! algorithm is the secured ,a" o% implementing encr"ption. Department of Computer Engineering, SIES GST Page 12 E-.ERIMENT NO/ ! DIFFIE HELLMAN 7EY E-CHANGE AIM ) - Write a program to implement $i%%ie &ellman !e" exchange algorithm. THEORY)- $i%%ie &ellman !e" exchange algorithm uses as"mmetric !e" principles %or the distri.ution o% s"mmetric !e"s to .oth parties in a communication net,or!. Ae" distri.ution is an important aspect o% con+entional algorithm and the entire sa%et" is dependent on the distri.ution o% !e" using secured channel. $i%%ie &ellman utili6es the pu.lic\ pri+ate !e" o% as"mmetric !e" cr"ptograph" to exchange the secret !e". $e%ine primiti+e root o% a prime num.er 7p7 as one ,hose po,ers generate all the integers %rom 1 to p:12 i.e. i% 7a7 is the primiti+e root o% a prime no 7p72 then2 a mod p 2 a 2 mod p 2 a 3 mod p2 ...a p:1 mod p generate all distinct integers %rom 1 to 3p:14 in some permutation. -he steps %or $i%%ie &ellman !e" exchange algorithm are8 S#e" 0 8 1B*)AB 0E)B;C EBECE=-S Select an" prime no 8 7>7 Calculate the primiti+e root o% > 8 7a7 such that aQ> S#e" 3 8 ASGCCE-R;C AEG 1E=ERA-;*= )G ESER 7A7 Select a random num.er as the pri+ate !e" FA ,here FA Q > Calculate the pu.lic !e" GA ,here GA 9 a F A mod > S#e" 4 8 AEG 1E=ERA-;*= )G ESER 7)7 Select a random num.er as the pri+ate !e" F) ,here F) Q > Calculate the pu.lic !e" G) ,here G) 9 a F ) mod > S#e" 4 8 Exchange the +alues o% pu.lic !e" .et,een A \ ) S#e" : 8 SGCCE-R;C AEG 3A4 1E=ERA-;*= )G ESER 7A7 A9 G) F A mod > S#e" ! 8 SGCCE-R;C AEG 3A4 1E=ERA-;*= )G ESER 7)7 Department of Computer Engineering, SIES GST Page 13 A9 GA F ) mod > CONCLUSIO=8- ;t can .e easil" .e pro+ed that the !e" A generated ." this algorithm ." .oth parties are the same. Department of Computer Engineering, SIES GST Page 14 E-.ERIMENT NO/ DIGITAL SIGNATURE AIM ) - Write a program to generate digital signature using RSA. THEORY)- A $igital Signature is a construct ,hich helps achie+e non:repudiation o% *rigin 3ie. *rigin ;ntegrit"4 o% data. )" digitall" signing the document2 the person ,ho signs it assures that he is the author o% the document or the message that ,as signed. -,o main Securit" considerations should .e ta!en into account ,hen implementing $igital Signatures. 1. Sign the message and then encr"pt the signed message 2. Sign the &ash o% the message instead o% the entire message Al'&ri#,m With the a.o+e considerations2 the algorithm .elo, can .e used %or implementing pu.lic !e" cr"ptograph" in /a+a. 1. Encr"pt the message using a s"mmetric !e". 2. Concatenate the s"mmetric !e" V &ash o% s"mmetric !e" V &ash o% message. 3. Encr"pt the concatenated string using the recei+er]s pu.lic !e". 4. Sign the data to .e transmitted 3Encr"pted s"mmetric !e" V &ash o% the !e" V &ash o% message4. . Validate the Signature. #. $ecr"pt the message using Recei+er pri+ate !e" to get the s"mmetric !e". '. Validate the integrit" o% the !e" using the &ash o% the !e". Department of Computer Engineering, SIES GST Page 15 (. $ecr"pt the actual message using the s"mmetric !e" ,hich has .een decr"pted and parsed and chec!ed %or integrit". O. Compute Cessage $igest o% data. 1K. Validate i% the Cessage $igest o% the decr"pted text matches the Cessage $igest o% the *riginal Cessage. CONCLUSIO=8- -here is a need %or authenticating critical transactions especiall" in the %inancial World. ;% Alice has agreed to trans%er ^x to )o.2 then there had to .e a ,a" %or )o. to .e sure that8 1. ;t ,as Alice ,ho per%ormed the transaction and not someone else impersonating Alice 3Authentication4 2. -he amount agreed ." Alice is ^x 3;ntegrit"4 3. Alice could not dispute her statement o% transacting ^x to )o. 3=on:Repudiation o% *rigin4 A.o+e mentioned can .e achie+ed ,ith $igital Signatures. Department of Computer Engineering, SIES GST Page 16 E-.ERIMENT NO/ ; (UFFER O*ERFLO< ATTAC7 AIM ) - Write a program to implement )u%%er *+er%lo, Attac!. THEORY)- Core data is put into a holding area than it can handle 3Bac! o% .ound chec!ing4. A technicall" inclined user ma" exploit stac!:.ased .u%%er o+er%lo,s to manipulate the program to their ad+antage in one o% se+eral ,a"s8 )" o+er,riting a local +aria.le that is near the .u%%er in memor" on the stac! to change the .eha+iour o% the program ,hich ma" .ene%it the attac!er. )" o+er,riting the return address in a stac! %rame. *nce the %unction returns2 execution ,ill resume at the return address as speci%ied ." the attac!er2 usuall" a user input %illed .u%%er. )" o+er,riting a %unction pointer2or exception handler2 ,hich is su.se>uentl" executed. With a method called ItrampoliningI2 i% the address o% the user:supplied data is un!no,n2 .ut the location is stored in a register2 then the return address can .e o+er,ritten ,ith the address o% an opcode ,hich ,ill cause execution to Jump to the user supplied data. ;% the location is stored in a register R2 then a Jump to the location containing the opcode %or a Jump R2 call R or similar instruction2 ,ill cause execution o% user supplied data. -he locations o% suita.le opcodes2 or ."tes in memor"2 can .e %ound in $BBs or the executa.le itsel%. &o,e+er the address o% the opcode t"picall" cannot contain an" null characters and the locations o% these opcodes can +ar" .et,een applications and +ersions o% the operating s"stem. CONCLUSIO=8- Department of Computer Engineering, SIES GST Page 17 C and CVV pro+ide no .uilt:in protection against accessing or o+er,riting data in an" part o% memor"@ more speci%icall"2 the" do not chec! that data ,ritten to a .u%%er is ,ithin the .oundaries o% that .u%%er. E-.ERIMENT NO/ = STEGNOGRA.HY AIM ) - -o stud" Stegnograph" ." storing a secret !e" in a /0E1 image. THEORY)- $igital stegnograph" concerns pri+ac" o% in%ormation under sur+eillance. Steganal"sis is the art o% detecting an" hidden message on the communication channel. ;% the existence o% the hidden message is re+ealed2 the goal o% steganograph" is de%eated. ?or all o% the stegnographic s"stems2 the most important and %undamental re>uirement is undetect a.ilit". -he hidden message should not .e detected ." an" other people. ;n addition2 the media ,ith hidden message2 called the stegomedia2 are indistinguisha.le %rom their original ones2 called the co+er:media. ?or /0E1 images2 /steg 3method to implement stegnogaph"4 em.eds the hidden message ." modulating the rounding choices either up or do,n in the >uanti6ed $C- conceits. -he a.ilit" o% em.edding messages in the /0E1 %ormat is an ad+antage o% this tool2 since most images are stored in /0E1 %ormat and trans%erred in the ;nternet. =ote that the do,ngrade image:delit" caused ." the em.edding process depends not onl" on the amount o% em.edding messages .ut also on the >ualit" %actor setting in /0E1 compression. ;% the >ualit" %actor is lo,2 the em.edding capacit" should .e limited in order to satis%" the impercepti.le re>uirement. CONCLUSIO=8- -he main ad+antage o% this techni>ue is that it is ro.ust to image modi%ication. &o,e+er2 the shared in%ormation .e%ore communication is dependent on the length o% the secret message2 i.e.2 the pa"load o% the s"stem is limited. Department of Computer Engineering, SIES GST Page 1 Department of Computer Engineering, SIES GST Page 19