Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Cryptography and network security, Summaries of Network Design

In the digital age, cryptography has evolved to address the encryption and decryption of private communications through the internet and computer systems, a branch of cyber and network security, in a manner far more complex than anything the world of cryptography had seen before the arrival of computers.

Typology: Summaries

2021/2022

Uploaded on 01/16/2022

Jaqua
Jaqua 🇦🇺

9 documents

1 / 29

Toggle sidebar

Related documents


Partial preview of the text

Download Cryptography and network security and more Summaries Network Design in PDF only on Docsity! COURSE FILE Subject! | CRYPTOGRAPHY & NETWORK SECURITY LAB Academic Year: 2021 — 22 Name of the Faculty : MEGHANA PANDITHA/ SRAVAN Department : CSE Branch/Year/Semester: CSE / Ill / Il PO1 |An ability to apply knowledge of computing, mathematics, science, and engineering |fundamentals appropriate to the discipline. PO2 |An Ability to Identify, formulate and analyze complex engineering problems, solving them by lapplying principles of mathematics and engineering sciences. PO3 |An ability to design, effective and efficient solutions for problems to meet the requirements. PO4 Conduct investigations of complex problems using research-based knowledge and methods lincluding design of experiments, analysis and interpretation of data, to provide valid conclusions PO5 |An ability to adopt and apply modern technical concepts, tools and practices. PO6 |An ability to analyze the impact of computing on individuals, organizations and society. PO7 |Apply knowledge and skill set to develop solutions by considering environmental and sustainability constraints. PO8 |An understanding of professional, ethical, legal, security and social issues and responsibilities lwith respect to technology and tools. PO9 |Function effectively as an individual, and as a member or leader in diverse teams. PO 10 |An ability to communicate effectively. PO 11 |Ability to deliver cost effective solutions and contribute towards project management. PO 12 |Ability to engage in lifelong learning to abreast with modern technologies and practices. Professional Skills and Foundations of Software development: Ability to analyze, design and) PSO 1 implement applications by adopting the dynamic nature of Software developments. (Applications of Computing and Research Ability: Ability to use knowledge in cutting edge PSO 2 jtechnologies in identifying societal problems, research gaps and to render solutions with} innovative ideas. I COURSE OVERVIEW: The objective of this course o To know about various encryption and decryption techniques. o Tounderstand the concept of Public key cryptography. o Toencrypt or decrypt data, create their own key using various tools and languages. o To study about message authentication and hash functions. o To impart knowledge on Network security. PREREQUISITES: Level Credits Periods/Weeks Prerequisites UG 2 3 Introduction to Cryptography and Network Security. Cryptography, which translates as "secret writing,” refers to the science of concealing the meaning of data so only specified parties understand a transmission's contents. Cryptography has existed for thousands of years; for most of history, however, the users of cryptography were associated with a government or organized group and were working to conceal secret messages from enemies. These days, millions upon millions of secure, encoded transmissions happen online each day -- and cryptographic standards are used to protect banking data, health information, and much more. Without cryptography, e- commerce as we know it would be impossible. Since online security threats evolve so quickly, there are dozens of different schools of thought on how best to use encryption to enhance network security -- not just for governments, but for businesses and end users, too. Network Security and cryptography go hand in hand, where in order to send data, certain measures are taken to secure or encrypt the message in order to keep it secret and private. This lab manual shows the programs that are to be executed by the students, where they will learn to encrypt and decrypt data using different methodologies. Lab Code:- e Students should report to the concerned lab as per the time table. e Students who turn up late to the labs will in no case be permitted to do the program schedule for the day. e After completion of the program, certification of the concerned staff in-charge in the observation book is necessary. e Student should bring a notebook of 100 pages and should enter the readings/observations into the notebook while performing the experiment. e The record of observations along with the detailed experimental procedure of the experiment in the immediate last session should be submitted and certified staff member in-charge. e Not more than 3-students in a group are permitted to perform the experiment on the set. e The group-wise division made in the beginning should be adhered to and no mix up of students among different groups will be permitted. e T he components required pertaining to the experiment should be collected from stores in-charge after duly filling in the requisition form. e When the experiment is completed, should disconnect the setup made by them, and should return all the components/instruments taken for the purpose. e Any damage of the equipment or burn-out components will be viewed seriously either by putting penalty or by dismissing the total group of students from the lab for the semester/year. e Students should be present in the labs for total scheduled duration. e Students are required to prepare thoroughly to perform the experiment before coming to laboratory. S.No. {Experiment No. NAME OF THE EXPERIMENT 1 1 |Write a C program that contains a string with value “Hello World”. it should XOR each character in the string with 0 and displays the result. 2 2 |Write a C program that contains a string with value “Hello World”. it should AND or/and XOR each character in the string with127 and displays the result. 3 3 Java program to perform encryption and decryption using i. Caesar cipher. ii. Substitution Cipher. iii. Hill Cipher. 4 4 Write a program to implement DES algorithm logic. 5 5 Write a program to implement Blowfish algorithm logic. 6 6 Write a program to implement Rijndael algorithm logic 7 7 Write RC4 logic using java cryptography; encrypt text using |blowfish. Create your own key using java key tool 8 8 (To implement RSA algorithm using java language. 9 9 Implement the Diffie-Hellman Key Exchange mechanism using HTML land JavaScript. 10 10 (Calculate the message digest of a text using the SHA-1 algorithm in JAVA. 11 11 Calculate the message digest of a text using the MDS algorithm in JAVA. EXPERIMENT NO: 1. NAME OF THE EXPERIMENT: XOR a string with zero. AIM: To contain a string with value “Hello World” and convert each character in the string into 0 using XOR. SOURCE CODE: int result; clrscr(); printf("\n Enter the plain text:"); scanf("%s", plain); printf("\n Enter the key value:"); scanf("%d", &key); printf("\n \n \t PLAIN TEXt: %s" plain); printf("\n \n \t ENCRYPTED TEXT: "); for(i = 0, length = strlen(plain); i < length; i++) { cipher[i]=plain[i] + key; if (isupper(plain[i]) && (cipher[i] > 'Z')) cipher[i] = cipher[i] - 26; if (islower(plain[i]) && (cipher[i] > 'z')) cipher[i] = cipher[i] - 26; printf("%c", cipher[i]); } printf("\n \n \t AFTER DECRYPTION : "); for(i=0;i<length;i++) { plain[i]=cipher[i]-key; if(isupper(cipher[i])&&(plain[i]<'A')) plain[i]=plain[i]+26; if(islower(cipher[i])&&(plain[i]<'‘a')) plain[i]=plain[i]+26; printf("%c".plain[i]); } getch(); } Output:- Enter plain text: hello Enter key value: 3 Encryption: khoor After decryption: hello b) Substitution Cipher #include<stdio.h> #include<conio.h> #include<string.h> #include<ctype.h> #define MX 5 void playfair(char ch1,char ch2, char key[MX][MX]) { int i,j,w.x,y.Z5 FILE “out; if((out=fopen("cipher.txt","a+"))==NULL) { printf("File Currupted."); } for(i=0;i<MX;i++) { for(j=0;j<MX;j++) { if(chl==key[i][j]) { wei; x=]; } else if(ch2==key[i][j]) { y=i; z=); Wy /printf("%d%d %d%d" w,x.y,Z); if(w==y) { x=(x+1)%5;z=(z+1)%5; printf(" %c%c",key[w][x],keyLy][z}); fprintf(out, "%c%c" .key[w][x],keyly][z]); } else if(x==z) { w=(w+1)%5;y=(y+1)%5; printf("%c%c" .key[w][x],keyLy][z); fprintf(out, "%c%c" .key[w][x],key[y][z]); } else { printf("%c%c" key[w][z].keyLy]Lx]); fprintf(out, "%c%c" .key[w][z].keyly][x]); } fclose(out); } void main() { int i,j,.k=0,1,m=0,n; char key[MX][MX],keyminus[25],keystr[10],str[25]={0}; char alpa[26]={'A‘,'B','C','D''E\'F,'G','H',T',J',K''L',"M clrscr(); printf("\nEnter key:"); gets(keystr); printf("\nEnter the plain text:"); gets(str); n=strlen(keystr); //convert the characters to uppertext for (i=0; i<n; i++) { if(keystr[i else if(keystr[i]=='J')keystr[i keystr[i] = toupper(keystr[i]); } //convert all the characters of plaintext to uppertext for (i=0; i<strlen(str); i++) TYUSVWYXYYZ'}; str[i] = toupper(str[i]); } J=0; for(i=0;i<26;i++) printf(" Yc" ,d[i]+65); for(i=0;i<3;i++) { t=0; for(j=0;j<3;j++) { t=t+(b[i] fj ]*dUD; } c[i]=t%26; } printf("\nDecrypted Cipher Text :"); for(i=0;i<3;i++) printf(" %c",c[i]+65); getch(); return 0; } Output:- Enter plain text: ACT 0219 Encrypted data: PON Decrypted data: A C T EXPERIMENT NO: 4. NAME OF THE EXPERIMENT: DES Program. AIM: To execute DES program using Java. SOURCE CODE: import javax.swing.*; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeyS pec; import java.util.Random ; class DES { byte[] skey = new byte[1000]; String skeyString; static byte[] raw; String inputMessage, encryptedData, decryptedMessage; public DES() { try { generateSymmetricKey(); inputMessage=JOptionPane.showInputDialog(null,"Enter message to encrypt"); byte[] ibyte = inputMessage.getBytes(); byte[] ebyte=encrypt(raw, ibyte); String encryptedData = new String(ebyte); System.out.printIn("Encrypted message "+encryptedData); JOptionPane.showMessageDialog(null,"Encrypted Data"+"\n"+encryptedData); byte[] dbyte= decrypt(raw.ebyte); String decryptedMessage = new String(dbyte); System.out.printIn("Decrypted message"+decryptedMessage); JOptionPane.showMessageDialog(null,"Decrypted Data"+"\n"+decryptedMessage); } catch(Exception e) { System.out.printIn(e); } } void generateSymmetricKey() { try { Random r = new Random(); int num = r.nextInt(10000); String knum = String.valueOf(num); byte[] knumb = knum.getBytes(); skey=getRawKey(knumb); skeyString = new String(skey); System.out.printIn("DES Symmetric key = "+skeyString); } catch(Exception e) { System.out.printIn(e); } } private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("DES"); SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); sr.setSeed(seed); kgen.init(56, sr); SecretKey skey = kgen.generateKey(); raw = skey.getEncoded(); return raw; } private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw,"DES"); Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] encrypted = cipher.doFinal(clear); return encrypted; } private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "DES"); Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte[] decrypted = cipher.doFinal(encrypted); return decrypted; } public static void main(String args[]) { DES des = new DES(); } } Output: Enter the string: Welcome String To Encrypt: Welcome Encrypted Value : BPQMwcOwKvg= Decrypted Value : Welcome Encrypted string: aa733b3a3b965bbee 14e21505b83b005223 1 1 ab6f8e305ad755 2474 1613 1b13 Original string: AES still rocks! 414553207374696c6c20726f636b732121 EXPERIMENT NO: 7. NAME OF THE EXPERIMENT:RC4 AIM: a) To execute RC4 logic in java using Java Cryptography. b) To encrypt text “Hello World” using Blowfish. c) To create your own key, using Java Key tool. SOURCE CODE: a. RC4 logic in Java. import java.io.*; public class rce4 { public static void main(String args[])throws IOException { int temp=0; String ptext; String key; int s[]=new int[256]; int k[]=new int[256]; DataInputStream in=new DatalnputStream(System.in); System.out.print(‘(\nENTER PLAIN TEXT\t”); ptext=in.readLine(); System.out.print(“\n\nENTER KEY TEXT\t\t”); key=in.readLine(); char ptextc[]=ptext.toCharArray(); char keyc[]=key.toCharArray(); int cipher[]=new int[ptext.length()]; int decrypt[]=new int[ptext.length()]; int ptexti[]=new int[ptext.lengthQ]; int keyi[]=new int[key.length()]; for(int i=0;i<ptext.lengthQ);i++) extiil-tindptextelil tortie i=0;i<key.length();i++) Kobi for(int i=0;i<255;i++) int j=0; for(int i=0;i<255;i++) { j=G+sli]+k[i])%256; Li}; int z=0; for(int 1=0;l<ptext.lengthQ);1++) { i=(14+1)%256; j=G+sli])%256; temp=s[i]; slil=stj]s s[j]=temp; z=s[(s[i]+s[j])%256]; cipher[l]=zptexti[]]; decrypt[1]=z’cipher[l]; } System.out.print(“\n\nENCR YPTED:\t\t”); display(cipher); System.out.print(‘\n\nDECR YPTED:\t\t”); display(decrypt); } static void display(int disp[]) { char convert[]=new char[disp.length]; for(int 1=0;l<disp.length;1++) { convert[1]=(char)disp[1]; System.out.print(convert[1]); } } Output: ENTER PLAIN TEXT RC4 PROGRAM ENTER KEY TEXT A ENCRYPTED: ??-??,+?,uFJ| DECRYPTED: RC4 PROGRAM b. Encrypt the text “Hello world” using Blowfish. Source Code: import javax.crypto.Cipher; import javax.crypto. KeyGenerator; import javax.crypto.SecretKey; import javax.swing.JOptionPane; public class BlowFishCipher { public static void main(String[] args) throws Exception { // create a key generator based upon the Blowfish cipher KeyGeneratorkey generator = KeyGenerator.getInstance(""Blowfish" ); // create a key SecretKeysecretkey = keygenerator.generateKey(); // create a cipher based upon Blowfish Cipher cipher = Cipher.getInstance("Blowfish"); // initialise cipher to with secret key cipher.init(Cipher. ENCRYPT_MODE, secretkey); // get the text to encrypt String inputText = JOptionPane.showInputDialog("Input your message: "); // encrypt message byte[] encrypted = cipher.doFinal(inputText.getBytes()); // re-initialise the cipher to be in decrypt mode cipher.init(Cipher. DECRYPT_MODE, secretkey); // decrypt message byte[] decrypted = cipher.doFinal(encrypted); // and display the results JOptionPane.showMessageDialog(JOptionPane. getRootFrame(), "\nEncrypted text: "+ new String(encrypted) + "\n" + "\nDecrypted text: " + new String(decrypted)); System.exit(0); } } Output: Input your message: Hello world Encrypted text: 3000&&(*& *414 Decrypted text: Hello world c. Steps to create a Self Signed Certificate using Java Keytool. import javax.crypto.spec. DHParameterS pec; import javax.crypto.spec. DHPublicKeyS pec; public class DiffeHellman { public final static int pValue = 47; public final static int gValue = 71; public final static int XaValue = 9; public final static int XbValue = 14; public static void main(String[] args) throws Exception { // TODO code application logic here BigInteger p = new BigInteger(Integer.toString(pValue)); BigInteger g = new BigInteger(Integer.toString(gValue)); BigIntegerXa = new BigInteger(Integer.toString(XaValue)); BigIntegerXb = new BigInteger(Integer.toString(XbValue)); createKey(); intbitLength = 512; // 512 bits SecureRandomrnd = new SecureRandom(); p = BigInteger.probablePrime(bitLength, rnd); g = BigInteger.probablePrime(bitLength, rnd); createSpecificKey(p, g); } public static void createKey() throws Exception { KeyPairGeneratorkpg = KeyPairGenerator.getInstance("DiffieHellman"); kpg.initialize(512); KeyPairkp = kpg.generateKeyPair(); KeyFactorykfactory = KeyFactory.getInstance("DiffieHellman"); DHPublicKeySpeckspec = (DHPublicKeyS pec) kfactory.getKeySpec(kp.getPublic(), DHPublicKeySpec.class); System.out.printIn("Public key is: " +kspec); } public static void createSpecificKey(BigInteger p, BigInteger g) throws Exception { KeyPairGeneratorkpg = KeyPairGenerator.getInstance("DiffieHellman"); DHParameterSpecparam = new DHParameterSpec(p, g); kpg.initialize(param); KeyPairkp = kpg.generateKeyPair(); KeyFactorykfactory = KeyFactory.getInstance("DiffieHellman"); DHPublicKeySpeckspec = (DHPublicKeyS pec) kfactory.getKeySpec(kp.getPublic(), DHPublicKeySpec.class); System.out.printIn("\nPublic key is : " +kspec); } } Output: Public key is: javax.crypto.spec.DHPublicKeySpec@S5afd29 Public key is: javax.crypto.spec.DHPublicKeySpec@997 lad EXPERIMENT NO: 10. NAME OF THE EXPERIMENT: SHA-1. AIM: To calculate message digest of a text using SHA-1 algorithm in Java. SOURCE CODE: import java.security.*; public class SHA { public static void main(String[] a) { try { MessageDigest md = MessageDigest.getInstance("SHA1"); System.out.println(""Message digest object info: "); System.out.println(" Algorithm = " +md.getAlgorithm()); System.out.println(" Provider = " +md.getProvider()); System.out.printin(" ToString = " +md.toString(); String input = ""; md.update(input.getBytes()); byte[] output = md.digest(); System.out.printin(); System.out.printin("SHA1(\""+input+"\") = " +bytesToHex(output)); input = "abc"; md.update(input.getBytes()); output = md.digest(); System.out.printin(); System.out.println("SHAI(\""+input+"\") = input = "abcdefghijklmnopqrstuvwxyz"; md.update(input.getBytes()); output = md.digest(); System.out.printin(); System.out.println("SHA1(\"" +input+"\") = " +bytesToHex(output)); System.out.printin(""); } catch (Exception e) { System.out.printin("Exception: " +e); } } public static String bytesToHex(byte[] b) { +bytesToHex(output)); char hexDigit[] = ('0','I','2', '3', 4", '5', '6,'7','8','9'A', 'B', 'C, 'D','E', 'F}; StringBufferbuf = new StringBuffer(); for (int j=0; j<b-length; j++) { buf.append(hexDigit[(b[j] >> 4) & Ox0f]); buf.append(hexDigit[b[j] & Ox0f]); } Return buf.toString(); } } OUTPUT: Message digest object info: Algorithm = SHAI Provider = SUN version 1.6 ToString = SHA1 Message Digest from SUN, <initialized> SHA1("") = DA39A3EESE6B4B0D3255BFEF95601890AFD80709 SHA1("abc") = A9993E3647068 16ABA3E257 17850C26C9CDOD89D SHA1("abcdefghijkImnopqrstuvwxyz") =32D10C7B8CF96570CA04CE37F2A 19D8424 OD3A89
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved