CNS Labmanual 2024
CNS Labmanual 2024
CNS Labmanual 2024
LAB
Prepared by
Mr. M.KRISHNA KANTH
Code: B6202
Page 1 of 72
SECTION-A: CLASS DOCUMENTS
Institute Vision
To be a premier centre of professional education and research, offering
quality programs in a socio-economic and ethical ambience.
Institute Mission
1. To impart knowledge of advanced technologies using state-of-the-art
infrastructural facilities.
2. To inculcate innovation and best practices in education, training and
research.
3. To meet changing socio-economic needs in an ethical ambience.
Page 2 of 72
Programme Educational Objectives (PEOs)
PEO I:
To impart with a sound knowledge in scientific and engineering technologies necessary to
formulate, analyze, design, and implement solutions to computer technology related problems.
PEO II:
To carry out research in frontier areas of computer science and engineering with the
capacity to learn independently throughout life to develop new technologies.
PEO III:
To train to exhibit technical, communication and project management skills in their
profession and follow ethical practices.
PEO IV:
To possess leadership and team working skills to become a visionary and an inspirational
leader and entrepreneur.
Programme Outcomes
PO Programme Outcomes
Page 3 of 72
PO 4 Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
PO 5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO 6 The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
PO 7 Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
PO 8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
Page 4 of 72
MALLA REDDY ENGINEERING COLLEGE
(Autonomous)
Maisammaguda, Dhullapally, Post via Kompally, NAAC A++
Secunderabad – 500100.
MID MARKS
CNS
AENUGULA SAI
2 21J41A62D2 MANOHAR
ARRAM SAI
LAXMI
3
21J41A62D3 PRASANNA
AVATURI NAGA
4 21J41A62D4 SAI AMEYA
BADAVATH
5 21J41A62D5 KALYANI
BHUKYA NITHISH
9 21J41A62D9 KUMAR
BIRAVALLI
10 21J41A62E0 NIRMAL KUMAR
BUCHHAIAHGARI
11 21J41A62E1 ABHINAY REDDY
BYSANI
MANAHOR
12
21J41A62E2 KUMAR
Page 5 of 72
CHEKILAM SAL
13 21J41A62E3 KRISHNA
CHILAKAPATI
14 21J41A62E4 NAGARAJU
DIGGIREDDY SAI
PRAANAVI
15
21J41A62E5 SNEHA REDDY
DUSTHAKAR
16 21J41A62E6 PAVAN KUMAR
EEGA SAKETH
17 21J41A62E7 REDDY
ELANKI SHRAVAN
18 21J41A62E8 KUMAR REDDY
ELURI
SIDDHARTHA
19
21J41A62E9 CHOWDARY
GANTHALA
22 21J41A62F2 TARUN
GOLLAPALLI
23 21J41A62F3 SAHITHI
GUNDEPAKA
24 21J41A62F4 PRADEEP
KANAPURAM
28 21J41A62F9 HARI KRISHNA
29 21J41A62G0 KARANGULA
SAMUEL
Page 6 of 72
JAYANTH
KATTAMURI
VENKATA
30
21J41A62G1 AKSHITHA
KONDAM
31 21J41A62G2 YASHWANTH
LINGAREDDY
34 21J41A62G5 POOJWALA
21J41A62G6 M PRANATHI
35
MALE
SAIGANESH
36
21J41A62G7 GOUD
MOLUGURI
39 21J41A62H1 ANIRUD
MUDAVATH
40 21J41A62H2 VENKATESH
MURIKINTI
41 21J41A62H3 VYSHNAVI
NALLAVELLY
42 21J41A62H4 LALITH REDDY
NUNUGONDA
43 21J41A62H5 HANSIKA
PATTIPAKALA
44 21J41A62H6 ROHAN
PULLAGURLA
45 21J41A62H7 RAGHU
46 21J41A62H8 PUNUGOTI
Page 7 of 72
AKSHITHA
S GYANJOTH
49 21J41A62J1 SINGH
SUKKA
55 21J41A62J8 MANIKIRAN
THOLLAMADUGU
SIVA KUMAR
56
21J41A62J9 REDDY
UJWALA SAI
57 21J41A62K0 PUVVULA
VEERAVALLI
58 21J41A62K1 DHARMA TEJA
VEDULLA
61 21J41A62K4 ANJANA
KAMISETTI SAI
62 22J45A6213 TEJA
AMBIDI
22J45A6214
63 SRICHARAN
Page 8 of 72
SRIHAN
PERUMANDLA
22J45A6216
65 GANESH
BHUKYA
22J45A6217
66 SOUNDARYA
RATHLAVATH
22J45A6218
67 RAMESH NAYAK
PABBATI
22J45A6219
68 BHAVANA
MUSIDIPALLI
69 22J45A6220 NAVEEN KUMAR
20J41A6235 MM HUSSAIN
70
20J41A6256 M.SAHITH
71
Page 9 of 72
Page 10 of 72
TIME TABLE
(Individual)
NAME-Mr.Krishnakanth SUBJECT-IOT-CN,CS-CNS
3.25
9.30- 10.20- 11.10- 11.20- 12.10- 1.00- 1.45- 2.35-
-
10.20 11.10 11.20 12.10 1.00 1.45 2.35 3.25
4.15
MO CNS
CNS LAB CNS
N LAB
III CS
TUE ACD III CS ACD LAB CNS
LAB LUNC
BREAK
H
WED CN CNS CN
THU CN CNS CN
FRI CN CNS
SAT CN
Page 11 of 72
TIME TABLE
(Class)
Page 12 of 72
SECTION – B: COURSE DOCUMENTS
B1 Course Syllabus
2023-24
MALLA REDDY ENGINEERING COLLEGE B.Tech.
Onwards
(Autonomous) V Semester
(MR-21)
Code: A6203 L T P
Cryptography and Network Security
Credits: 3 3 - -
Course Objectives:
Explain the objectives of information security
Explain the importance and application of each of confidentiality, integrity, authentication and
availability
Understand various cryptographic algorithms.
Understand the basic categories of threats to computers and networks
Describe public-key cryptosystem.
Describe the enhancements made to IPv4 by IPSec.
Understand Intrusions and intrusion detection
Discuss the fundamental ideas of public-key cryptography
Generate and distribute a PGP key pair and use the PGP package to send an encrypted email message.
Discuss Web security and Firewalls
MODULE - I
Security Concepts: Introduction, The need for security, Security approaches, Principles of security, Types of
Security attacks, Security services, Security Mechanisms, A model for Network Security
Cryptography Concepts and Techniques: Introduction, plain text and cipher text, substitution techniques,
transposition techniques, encryption and decryption, symmetric and asymmetric key cryptography,
steganography, key range and key size, possible types of attacks.
MODULE - II
Symmetric key Ciphers: Block Cipher principles, DES, AES, Blowfish, RC5, IDEA, Block cipher operation,
Stream ciphers, RC4.
Asymmetric key Ciphers: Principles of public key cryptosystems, RSA algorithm, Elgamal Cryptography,
Diffie-Hellman Key Exchange, Knapsack Algorithm.
MODULE - III
Cryptographic Hash Functions: Message Authentication, Secure Hash Algorithm (SHA-512),
Message authentication codes: Authentication requirements, HMAC, CMAC, Digital signatures, Elgamal
Digital Signature Scheme.
Key Management and Distribution: Symmetric Key Distribution Using Symmetric & Asymmetric
Encryption, Distribution of Public Keys, Kerberos, X.509 Authentication Service, Public – Key Infrastructure.
MODULE - V
E-Mail Security: Pretty Good Privacy, S/MIME IP Security: IP Security overview, IP Security architecture,
Authentication Header, Encapsulating security payload, combining security associations, Internet Key
Exchange
Case Studies on Cryptography and security: Secure Multiparty Calculation, Virtual Elections, Single sign
On, Secure Inter-branch Payment Transactions, Cross site Scripting Vulnerability
TEXT BOOKS:
1. Cryptography and Network Security - Principles and Practice: William Stallings, Pearson Education,
6th Edition
2. Cryptography and Network Security: Atul Kahate, Mc Graw Hill, 3rd Edition
REFERENCE BOOKS:
1. Cryptography and Network Security: C K Shyamala, N Harini, Dr T R Padmanabhan, Wiley India, 1st
Edition.
2. Cryptography and Network Security: Forouzan Mukhopadhyay, Mc Graw Hill, 3rd Edition
3. Information Security, Principles, and Practice: Mark Stamp, Wiley India.
4. Principles of Computer Security: WM. Arthur Conklin, Greg White, TMH
5. Introduction to Network Security: Neal Krawetz, CENGAGE Learning
6. Network Security and Cryptography: Bernard Menezes, CENGAGE Learning
Course Outcomes:
Student will be able to understand basic cryptographic algorithms, message and web authentication and
Security issues
Ability to identify information system requirements for both of them such as client and server
Ability to understand the current legal issues towards information security
CO- PO Mapping
(3/2/1 indicates strength of correlation) 3-Strong, 2-Medium, 1-Weak
Programme Outcomes(POs)
COS PO1 PO2 PO3 PO4 PO PO6 PO PO8 PO PO1 PO1 PO12
5 7 9 0 1
CO1 2 3 1
CO2 3 2 1
CO3 3 2 1
Institute Vision
To be a premier centre of professional education and research, offering quality programs in a socio-
economic and ethical ambience.
Institute Mission
4. To impart knowledge of advanced technologies using state-of-the-art infrastructural facilities.
5. To inculcate innovation and best practices in education, training and research.
6. To meet changing socio-economic needs in an ethical ambience.
Vision
To attain global standards in Computer Science and Engineering education, training, and research to meet the
growing needs of the industry with socio-economic and ethical considerations.
Mission
To impart quality education and research to undergraduate and postgraduate students in Computer Science and
Engineering.
To encourage innovation and best practices in Computer Science and Engineering utilizing state-of-the-art
facilities.
To develop entrepreneurial spirit and knowledge of emerging technologies based on ethical values and social
relevance.
Programme Outcomes
PO Programme Outcomes
PO 9 Individual and team work: Function effectively as an individual and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO 10 Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as,being able to comprehend and
write effective reports and design
PO 11 Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments.
PO 12 Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
2. Problem Analysis: Identify, formulate, research literature and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences and engineering
sciences.
3. Design / Development of Solutions: Design solutions for complex engineering problems and design
system components or processes that meet specified needs with appropriate consideration for public health
and safety, cultural, societal and environmental considerations.
4. Conduct investigations of complex problems using research-based knowledge and research methods
including design of experiments, analysis and interpretation of data and synthesis of information to provide
valid conclusions.
5. Modern Tool Usage: Select and apply appropriate techniques, resources, and modern engineering and IT
tools, including prediction and modeling, to broadly-defined engineering activities, with an understanding
of the limitations.
6. The Engineer and society: Demonstrate understanding of the societal, health, safety, legal and cultural
issues, and the consequent responsibilities relevant to engineering technology practice.
8. Ethics: Understand and commit to professional ethics and responsibilities and norms of engineering
technology practice.
9. Individual and Team work: Function effectively as an individual, and as a member or leader in diverse
technical teams.
10. Communication: Communicate effectively on Broadly-defined engineering activities with the engineering
community and with society at large, by being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear instructions.
11. Project Management and Finance: Demonstrate knowledge and understanding of engineering
management principles and apply the same to one’s own work, as a member and leader in a team and to
manage projects in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the ability to engage in independent and life-long
learning in specialized technologies.
*To be filled at the beginning of the semester with Academic Calendar as reference
logic
Write a C/JAVA program to
implement the BlowFish 1
algorithm logic
Write a C/JAVA program to
implement the Rijndael 1
algorithm logic.
Using Java Cryptography,
encrypt the text “Hello world”
1
using BlowFish. Create your
own key using Java keytool.
Write a Java program to
1
implement RSA Algoithm
Implement the Diffie-Hellman 1
algorithm in JAVA.
Calculate the message digest
of a text using the MD5 1
algorithm in JAVA.
CO- PO Mapping
(3/2/1 indicates strength of correlation) 3-Strong, 2-Medium, 1-Weak
Programme Outcomes(POs)
COS PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 2 3 1
CO2 3 2 1
AIM: Write a C program that contains a string (char pointer) with a value \Hello World’.
The program should XOR each character in this string with 0 and display the result.
PROGRAM:
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void main()
{ char str[]="HelloWorld";
char str1[11];
int i,len;
len=strlen(str)
;for(i=0;i<len;i++ )
str1[i]=str[i]^0;
printf("%c",str1[i]);
printf("\n");
Output:
Hello World
Hello World
AIM: Write a C program that contains a string (char pointer) with a value \Hello World’.
The program should AND or and XOR each character in this string with 127 and display
the result.
PROGRAM:
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
void main(){
char str[]="Hello World";
int i,len;
len = strlen(str);
for(i=0;i<len;i++){
printf("%c",str[i]&127);
}
printf("\n");
for(int i=0;i<len;i++){
printf("%c",str[i]^127);
}
printf("\n");
for(int i=0;i<len;i++){
printf("%c",str[i]|127);
}
printf("\n");
}
Output:
AIM: Write a Java program to perform encryption and decryption using the
following algorithms:
a) Ceaser Cipher
b) Substitution Cipher
c) Hill Cipher
PROGRAM:
Ceaser Cipher
#include <stdio.h>
#include <string.h>
#include<conio.h>
#include <ctype.h>
void main()
{
char plain[10], cipher[10];
int key,i,length;
int result;
Output:
Enter any String: Hello World Enter
the Key: 5
b) Substitution Cipher
PROGRAM:
import java.io.*;
import java.util.*;
for(int i=0;i<str.length();i++)
c = str.charAt(i); int j =
a.indexOf(c);
decrypt = decrypt+b.charAt(j);
Output:
Enter any string: aceho
a) Hill
Cipher PROGRAM:
import java.io.*; import
java.util.*; import java.io.*;
public class HillCipher {
inverse();
decrypt[i][j] = decrypt[i][j]+b[i][k]*res[k][j]; }
System.out.print("\nDecrypted string is : ");
System.out.print("\n");
for(int i=0;i<3;i++)
mes[i][0] = msg.charAt(i)-97;
float[][] c = a; for(int
i=0;i<3;i++) for(int
j=0;j<3;j++) {
//a[i][j]=sc.nextFloat();
if(i==j) b[i][j]=1;
else b[i][j]=0;
p = c[i][k];
q = c[k][k]; for(int
j=0;j<3;j++) { if(i!=k) {
c[i][j] = c[i][j]*q-p*c[k][j];
b[i][j] = b[i][j]*q-p*b[k][j];
}}}}
System.out.println(""); System.out.println("\nInverse
Matrix is : "); for(int i=0;i<3;i++) {
for(int j=0;j<3;j++)
System.out.print(b[i][j] + " ");
System.out.print("\n"); }
}}
Output:
Enter a 3 letter string: hai
Encrypted string is :fdx Inverse
Matrix is :
PROGRAM:
import java.util.*;
import javax.crypto.SecretKey;
= "ThisIsSecretEncryptionKey"; myEncryptionScheme =
DESEDE_ENCRYPTION_SCHEME; keyAsBytes =
myEncryptionKey.getBytes(UNICODE_FORMAT); myKeySpec
= new DESedeKeySpec(keyAsBytes);
Cipher.getInstance(myEncryptionScheme);
key = mySecretKeyFactory.generateSecret(myKeySpec);
try {
cipher.init(Cipher.ENCRYPT_MODE, key);
catch (Exception e) {
e.printStackTrace(); }
returnencryptedString; }
{ String decryptedText=null;
try {
cipher.init(Cipher.DECRYPT_MODE, key);
catch (Exception e) {
e.printStackTrace(); }
returndecryptedText; }
OUTPUT:
Enter the string: Welcome String To
Encrypt: Welcome
PROGRAM:
import java.io.*;
import javax.crypto.Cipher;
fin.close(); cout.close(); } }
OUTPUT:
Initialization Vector of the Cipher: dI1MXzW97oQ=
Contents of inputFile.txt: Hello World
PROGRAM:
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;
OUTPUT:
Input your message: Hello KGRCET
Encrypted text: 3ooo&&(*&*4r4
Decrypted text: Hello KGRCET
AIM: Using Java Cryptography, encrypt the text “Hello world” using BlowFish. Create
your own key using Java keytool.
PROGRAM:
import javax.crypto.Cipher; import
javax.crypto.KeyGenerator; import
javax.crypto.SecretKey; import
javax.swing.JOptionPane; public class
BlowFishCipher {
// create a key
// decrypt message
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: 3ooo&&(*&*4r4 Decrypted text:
Hello world
8. RSA Algorithm
PROGRAM:
import java.io.BufferedReader; import
java.io.InputStreamReader; import
java.math.*;
BigInteger n = p.multiply(q);
BigInteger n2 = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
BigInteger e = generateE(n2);
BigInteger e; BigInteger
gcd;
do {
y = x.nextInt(fiofn.intValue()-1);
String z = Integer.toString(y);
intGCD = gcd.intValue();
OUTPUT:
9. Diffie-Hellman
AIM: Implement the Diffie-Hellman Key Exchange mechanism using HTML and
JavaScript. Consider the end user as one of the parties (Alice) and the JavaScript
application as other party (bob).
PROGRAM:
import java.math.BigInteger; import
java.security.KeyFactory; import
java.security.KeyPair;
p = BigInteger.probablePrime(bitLength, rnd); g =
BigInteger.probablePrime(bitLength, rnd);
createSpecificKey(p, g);
KeyPairGeneratorkpg = KeyPairGenerator.getInstance("DiffieHellman");
kpg.initialize(512);
KeyPairkp = kpg.generateKeyPair();
KeyPairkp = kpg.generateKeyPair();
OUTPUT:
Public key is: javax.crypto.spec.DHPublicKeySpec@5afd29 Public
key is: javax.crypto.spec.DHPublicKeySpec@9971ad
10. SHA-1
AIM: Calculate the message digest of a text using the SHA-1 algorithm in JAVA.
PROGRAM:
import java.security.*; public
class SHA1 {
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.println(" ToString = " +md.toString());
input = "abc";
md.update(input.getBytes()); output =
md.digest(); System.out.println();
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
System.out.println();
catch (Exception e) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
OUTPUT:
Message digest object info:
Algorithm = SHA1
SHA1("abcdefghijklmnopqrstuvwxyz")=32D10C7B8CF96570CA04CE37F2A19D8424 0D3A89
PROGRAM:
import java.security.*; public
class MD5 {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
System.out.println("Message digest object info: ");
System.out.println(" Algorithm = " +md.getAlgorithm());
System.out.println(" Provider = " +md.getProvider());
System.out.println(" ToString = " +md.toString());
md.update(input.getBytes());
input = "abc";
md.update(input.getBytes()); output =
md.digest(); System.out.println();
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
System.out.println();
+bytesToHex(output)); System.out.println("");
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
return buf.toString(); } }
OUTPUT:
Message digest object
info: Algorithm = MD5
900150983CD24FB0D6963F7D28E17F72 MD5("abcdefghijklmnopqrstuvwxyz") =
C3FCD3D76192E4007DFB496CCA67E13B