Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 71

Department of Computer Science and Engineering (CS)

Lab Course File

III B. Tech I Semester

Subject: CRYPTOGRAPHY & NETWORK SECURITY

LAB

Prepared by
Mr. M.KRISHNA KANTH

Code: B6202

Academic Year 2023-24


Regulations: MR 21

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.

Maisammaguda, Dhulapally, (Post via Kompally), Secunderabad 500100


Email: csehod@mrec.ac.in website: http://www.mrec.ac.in

Programme Outcomes
PO Programme Outcomes

PO 1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
PO 2 Problem analysis: Identify, formulate, review research literature and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO 3 Design/development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal, and
environmental considerations.

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.

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 Communication: Communicate effectively on complex engineering activities with the
10 engineering community and with society at large, such as,being able to comprehend and
write effective reports and design
PO Project management and finance: Demonstrate knowledge and understanding of the
11 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 Life-long learning: Recognize the need for, and have the preparation and ability to
12 engage in independent and life-long learning in the broadest context of technological
change.

Page 4 of 72
MALLA REDDY ENGINEERING COLLEGE
(Autonomous)
Maisammaguda, Dhullapally, Post via Kompally, NAAC A++
Secunderabad – 500100.

MID MARKS

CNS

S.N Name of the INTERNAL-I INTERNAL-II Avera


Roll No ge
o Candidate
30
ADUMEKALA
1 21J41A62D1 SHIVA KUMAR

AENUGULA SAI
2 21J41A62D2 MANOHAR

ARRAM SAI
LAXMI
3
21J41A62D3 PRASANNA

AVATURI NAGA
4 21J41A62D4 SAI AMEYA

BADAVATH
5 21J41A62D5 KALYANI

21J41A62D6 BAIROJU SHIVANI


6
21J41A62D7 BATTU SRINIVAS
7
BATTULA
8 21J41A62D8 JAYANTH KUMAR

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

21J41A62F0 GAMPA HARISH


20
GANTALA
21 21J41A62F1 AVINASH

GANTHALA
22 21J41A62F2 TARUN

GOLLAPALLI
23 21J41A62F3 SAHITHI

GUNDEPAKA
24 21J41A62F4 PRADEEP

21J41A62F5 JUPALLI VIVEK


25
21J41A62F6 K ANIL
26
K TIRUMALA
27 21J41A62F7 SREEKAR RAO

KANAPURAM
28 21J41A62F9 HARI KRISHNA

29 21J41A62G0 KARANGULA
SAMUEL

Page 6 of 72
JAYANTH

KATTAMURI
VENKATA
30
21J41A62G1 AKSHITHA

KONDAM
31 21J41A62G2 YASHWANTH

21J41A62G3 KYASA KAVERI


32
LAVUDIYA
33 21J41A62G4 DATHAPRASAD

LINGAREDDY
34 21J41A62G5 POOJWALA

21J41A62G6 M PRANATHI
35
MALE
SAIGANESH
36
21J41A62G7 GOUD

21J41A62G9 MANOJU VILAS


37
MOHAMMAD
38 21J41A62H0 SAIFUDDIN

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

21J41A62H9 RAJOLI MOUNIKA


47
REPAKULA
48 21J41A62J0 GANESH

S GYANJOTH
49 21J41A62J1 SINGH

21J41A62J2 S SAI VINODH


50
21J41A62J3 S VIJAY KUMAR
51
21J41A62J4 SANTI VIDHATHA
52
21J41A62J5 SARA PRANEETH
53
SEELAM
CHARANDEEP
54
21J41A62J6 REDDY

SUKKA
55 21J41A62J8 MANIKIRAN

THOLLAMADUGU
SIVA KUMAR
56
21J41A62J9 REDDY

UJWALA SAI
57 21J41A62K0 PUVVULA

VEERAVALLI
58 21J41A62K1 DHARMA TEJA

21J41A62K2 V ESWAR REDDY


59
VATTIPALLY
60 21J41A62K3 SHASHANK

VEDULLA
61 21J41A62K4 ANJANA

KAMISETTI SAI
62 22J45A6213 TEJA

AMBIDI
22J45A6214
63 SRICHARAN

64 22J45A6215 PERUKA SAI

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)

MALLA REDDY ENGINEERING COLLEGE (Autonomous)


Dept of Computer Science and Engineering(CS)
TIME TABLE
Academic Year 2022-23
Branch : III B.Tech I Sem

9.30- 11.10- 12.10- 1.00- 1.45- 2.35-


10.20-11.10 11.20-12.10 3.25-4.15
10.20 11.20 1.00 1.45 2.35 3.25
MO
SS CNS LAB CNS LAB DS DAA CNS
N
TUE QA ACD LAB ACD LAB CNS ACD MF
WE BREA LUNC
DS MF SEM ACD CNS DS SPORTS
D K H
THU QA ACD DAA CNS DS DAA SEM
FRI ACD MF SEM DAA SEM CNS LIB
SAT DS SEM ACD DAA DS SEM ACD

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.

2 COMPUTER SCIENCE & ENGINEERING


MODULE - IV
Transport-level Security: Web security considerations, Secure Socket Layer and Transport Layer Security,
HTTPS, Secure Shell (SSH)
Wireless Network Security: Wireless Security, Mobile Device Security, IEEE 802.11 Wireless LAN, IEEE
802.11i Wireless LAN Security

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

3 COMPUTER SCIENCE & ENGINEERING


CO4 3 2 1
CO5 2 3 1

SECTION – B: COURSE DOCUMENTS


B1 Lab Syllabus – List of Experiments

S.NO. TOPIC PAGE NUMBER

Write a C program that contains a string (char pointer) with a


1 value \Hello World’. The program should XOR each character in 1
this string with 0 and displays the result.

Write a C program that contains a string (char pointer) with a


2 value \Hello World’. The program should AND or and XOR each 2
character in this string with 127 and display the result

Write a Java program to perform encryption and decryption using


the following algorithms:
3 3-9
a) Ceaser Cipher
b) Substitution Cipher
c) Hill Cipher
4 Write a Java program to implement the DES algorithm logic 10-12

Write a C/JAVA program to implement the BlowFish algorithm


5 13-14
logic

Write a C/JAVA program to implement the Rijndael algorithm


6 15
logic.

Using Java Cryptography, encrypt the text “Hello world” using


7 17-18
BlowFish. Create your own key using Java keytool.

8 Write a Java program to implement RSA Algoithm 19

4 COMPUTER SCIENCE & ENGINEERING


Implement the Diffie-Hellman Key Exchange mechanism using
HTML and JavaScript. Consider the end user as one of the
9 21-22
parties (Alice) and the JavaScript application as other party
(bob).

Calculate the message digest of a text using the SHA-1 algorithm


10 23-24
in JAVA.

Calculate the message digest of a text using the MD5 algorithm


11 25-26
in JAVA.

B2 Bloom’s Taxonomy (BT) Triangle & Blooms Action Verbs

Malla Reddy Engineering College


(Autonomous)
Department of Computer Science and Engineering-Cyber
Security

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.

5 COMPUTER SCIENCE & ENGINEERING


Malla Reddy Engineering College
(Autonomous)
Department of Computer Science and Engineering-Cyber
Security

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 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.

6 COMPUTER SCIENCE & ENGINEERING


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.

Maisammaguda, Dhulapally, (Post via Kompally), Secunderabad 500100


Email: csehod@mrec.ac.in website: http://www.mrec.ac.in

Programme Outcomes
PO Programme Outcomes

PO 1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
PO 2 Problem analysis: Identify, formulate, review research literature and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO 3 Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
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.

7 COMPUTER SCIENCE & ENGINEERING


PO 8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.

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.

Bloom’s Taxonomy Triangle

8 COMPUTER SCIENCE & ENGINEERING


9 COMPUTER SCIENCE & ENGINEERING
1 COMPUTER SCIENCE & ENGINEERING
0
1 COMPUTER SCIENCE & ENGINEERING
1
The Graduate Attributes for UG Engineering Student

1. Engineering Knowledge: apply Knowledge of mathematics, science, engineering fundamentals and an


engineering specialization to the solution of complex engineering problems.

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.

7. Environment and sustainability: Understand the impact of engineering/technology solutions in societal


and environmental context, and demonstrate knowledge of, and need for sustainable development.

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.

1 COMPUTER SCIENCE & ENGINEERING


2
PEO’s Mapping with PO’s
Program Outcomes(a-i)
Program Educational Objective
a b c d e f g h i
PEO I ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
PEO II ✓ ✓ ✓ ✓ ✓ ✓
PEO III ✓ ✓ ✓ ✓
PEO IV ✓ ✓ ✓ ✓ ✓

Subject Mapping with PEO’s


The components of the curriculum and their relevance to the POs and the PEOs
Programme curriculum grouping based on different components
Course Curriculum Content (%of number Total no of Total number
POs PEOs
Component of credits of the programme) contact hours of credits
III Year I Semester
Professional
Cryptography and Network Security 48 3 a,b,c,f,g, P1,P2
core
h

Subject Mapping with PO’s


Core engineering subjects and their relevance to Programme Outcomes including design experience.
Contribution of courses
Program Outcomes (a-i) Course outcomes
to program outcomes
III YEAR I SEMSTER
Course No. & Title a b c d e f g h i
✓ ✓ ✓ ✓ ✓ ✓ ✓ Differentiate Understand various
cryptographic algorithms.
Cryptography and  Understand the basic categories of
Network Security threats to computers and networks
 Describe public-key cryptosystem.

Year/ Course Program Highly Moderately


Outcomes
Sem Name Outcomes
Cryptography Differentiate Understand various a,b,c,d,e,f b,c d,e
III/I and Network cryptographic algorithms.

1 COMPUTER SCIENCE & ENGINEERING


3
 Understand the basic categories of
threats to computers and networks
 Describe public-key cryptosystem
Apply Describe public-key b,c,d,e B c,d,e
cryptosystem.
 Describe the enhancements made to
IPv4 by IPSec. various cryptographic
Security
algorithms.

Capable Understand Intrusions and a,c,d,f,g a,c,d f,g


intrusion detection
 Discuss the fundamental ideas of
public-key cryptography
Design Generate and distribute a PGP b,c,e b c,e
key pair and use the PGP package to
send an encrypted email message.

1 COMPUTER SCIENCE & ENGINEERING


4
B3 Laboratory Course Plan & Lesson Plan as per IQAC Format

MALLA REDDY ENGINEERING COLLEGE

LESSON PLAN– LABORATORY

Programme : B.Tech Year/Semester : III/ I


Subject/ Lab : CNS Academic Year : 2023-24
Name of the Faculty : Mr. M.KRISHNAKANTH Regulation : MR21

*To be filled at the beginning of the semester with Academic Calendar as reference

TLP : Teaching Learning Process , DM : Delivery Method


Hour Actua
Planned
Module I- : Security Concepts l
Count LLP DM Remarks
(Topics) / List of Experiments Date & Hr.
Date
*
& Hr.

Write a C program that


contains a string (char
pointer) with a value \Hello
World’. The program should 1
XOR each character in this
string with 0 and displays the
result.

1 COMPUTER SCIENCE & ENGINEERING


5
Write a C program that
contains a string (char
pointer) with a value \Hello
World’. The program should 1

AND or and XOR each


character in this string with
127 and display the result
Hour Write a Java program to

Count perform encryption and


Actua
decryption using the Planned
l
following algorithms:Ceaser LLP DM Remarks
Date & Hr.
Cipher Date
*
& Hr.
a) Substitution
Cipher
Hill Cipher
Write a Java program to
implement the DES algorithm 1

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

1 COMPUTER SCIENCE & ENGINEERING


6
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).
Calculate the message digest
of a text using the SHA-1 1

algorithm in JAVA.
Calculate the message digest
of a text using the MD5 1

algorithm in JAVA.

B4 CO-PO Mapping Logic (Venn diagram)

PEO’s Mapping with PO’s


Program Outcomes(a-i)
Program Educational Objective
a b c d e f g h i
PEO I ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
PEO II ✓ ✓ ✓ ✓ ✓ ✓
PEO III ✓ ✓ ✓ ✓
PEO IV ✓ ✓ ✓ ✓ ✓

Subject Mapping with PEO’s


The components of the curriculum and their relevance to the POs and the PEOs
Programme curriculum grouping based on different components
Course Curriculum Content (%of number Total no of Total number
POs PEOs
Component of credits of the programme) contact hours of credits
III Year I Semester
Professional CRYPTOGRAPHY AND NETWORK SECURITY
48 3 a,b,c,f,g, P1,P2
core
h

Subject Mapping with PO’s

1 COMPUTER SCIENCE & ENGINEERING


7
Core engineering subjects and their relevance to Programme Outcomes including design experience.
Contribution of courses
Program Outcomes (a-i) Course outcomes
to program outcomes
IV YEAR I SEMSTER
Course No. & Title a b c d e f g h i
✓ ✓ ✓ ✓ ✓ ✓ ✓ Differentiate Understand various
cryptographic algorithms.
Digital Forensics
 Understand the basic categories of
threats to computers and networks
 Describe public-key cryptosystem.

Year/ Course Program Highly Moderately


Outcomes
Sem Name Outcomes
Differentiate Understand various a,b,c,d,e,f b,c d,e
cryptographic algorithms.
 Understand the basic categories of
threats to computers and networks
 Describe public-key cryptosystem
Apply Describe public-key b,c,d,e B c,d,e
cryptosystem.
 Describe the enhancements made to
IPv4 by IPSec. various cryptographic
algorithms.
Digital
IV/I Forensics
Capable Understand Intrusions and a,c,d,f,g a,c,d f,g
intrusion detection
 Discuss the fundamental ideas of
public-key cryptography
Design Generate and distribute a PGP b,c,e b c,e
key pair and use the PGP package to
send an encrypted email message.
Design interactive algorithms for use b,c,d,e b,e c,d
on internet and Web security and
Firewalls.

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

1 COMPUTER SCIENCE & ENGINEERING


8
CO3 3 2 1
CO4 3 2 1
CO5 2 3 1

B5 Laboratory Manual Approved by HoD

CRYPTOGRAPHY & NETWORK SECURITY LAB

1. XOR a string with a Zero

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++ )

1 COMPUTER SCIENCE & ENGINEERING


9
{

str1[i]=str[i]^0;

printf("%c",str1[i]);

printf("\n");

Output:
Hello World
Hello World

2 COMPUTER SCIENCE & ENGINEERING


0
CRYPTOGRAPHY & NETWORK SECURITY LAB

2. XOR a string with a 127

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:

Hello World Hello


World Hello World

21 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

3. Encryption & Decryption using Cipher Algorithms

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;

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;

22 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

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]);
}
}

Output:
Enter any String: Hello World Enter
the Key: 5

Encrypted String is: MjqqtBtwqi


Decrypted String is: Hello World

23 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

b) Substitution Cipher
PROGRAM:

import java.io.*;
import java.util.*;

public class SubstitutionCipher {

static Scanner sc = new Scanner(System.in);

static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


public static void main(String[] args) throws IOException {

// TODO code application logic here


String a = "abcdefghijklmnopqrstuvwxyz";
String b = "zyxwvutsrqponmlkjihgfedcba";

System.out.print("Enter any string: ");


String str = br.readLine();

String decrypt = ""; char c;

for(int i=0;i<str.length();i++)

c = str.charAt(i); int j =
a.indexOf(c);

decrypt = decrypt+b.charAt(j);

System.out.println("The encrypted data is: " +decrypt);

24 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

Output:
Enter any string: aceho

The encrypted data is: zxvsl

25 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

a) Hill
Cipher PROGRAM:
import java.io.*; import
java.util.*; import java.io.*;
public class HillCipher {

static float[][] decrypt = new float[3][1];


static float[][] a = new float[3][3]; static
float[][] b = new float[3][3]; static float[][]
mes = new float[3][1]; static float[][] res =
new float[3][1];

static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


static Scanner sc = new Scanner(System.in); public static void main(String[] args)
throws IOException {

// TODO code application logic


here getkeymes();

for(int i=0;i<3;i++) for(int j=0;j<1;j++) for(int


k=0;k<3;k++) { res[i][j]=res[i][j]+a[i][k]*mes[k][j]; }
System.out.print("\nEncrypted string is : "); for(int
i=0;i<3;i++) { System.out.print((char)(res[i]
[0]%26+97)); res[i][0]=res[i][0];

inverse();

26 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

for(int i=0;i<3;i++) for(int


j=0;j<1;j++) for(int
k=0;k<3;k++) {

decrypt[i][j] = decrypt[i][j]+b[i][k]*res[k][j]; }
System.out.print("\nDecrypted string is : ");

27 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

for(int i=0;i<3;i++){ System.out.print((char)(decrypt[i]


[0]%26+97));

System.out.print("\n");

public static void getkeymes() throws IOException { System.out.println("Enter 3x3


matrix for key (It should be inversible): "); for(int i=0;i<3;i++)

for(int j=0;j<3;j++) a[i][j] =


sc.nextFloat();

System.out.print("\nEnter a 3 letter string: ");


String msg = br.readLine();

for(int i=0;i<3;i++)

mes[i][0] = msg.charAt(i)-97;

public static void inverse() { floatp,q;

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;

28 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

for(int k=0;k<3;k++) { for(int


i=0;i<3;i++) {

p = c[i][k];

q = c[k][k]; for(int
j=0;j<3;j++) { if(i!=k) {

29 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

c[i][j] = c[i][j]*q-p*c[k][j];

b[i][j] = b[i][j]*q-p*b[k][j];

}}}}

for(int i=0;i<3;i++) for(int


j=0;j<3;j++) { b[i][j] =
b[i][j]/c[i][i]; }

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 :

0.083333336 0.41666666 -0.33333334

-0.41666666 -0.083333336 0.6666667

0.5833333 -0.083333336 -0.33333334

Decrypted string is: hai

30 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

4. Java program for DES algorithm logic

AIM: Write a Java program to implement the DES algorithm logic.

PROGRAM:

import java.util.*;

import java.io.BufferedReader; import


java.io.InputStreamReader; import
java.security.spec.KeySpec; import
javax.crypto.Cipher;

import javax.crypto.SecretKey;

import javax.crypto.SecretKeyFactory; import


javax.crypto.spec.DESedeKeySpec; import
sun.misc.BASE64Decoder;

import sun.misc.BASE64Encoder; public


class DES {

private static final String UNICODE_FORMAT = "UTF8";

public static final String DESEDE_ENCRYPTION_SCHEME = "DESede";


privateKeySpecmyKeySpec; privateSecretKeyFactorymySecretKeyFactory;

private Cipher cipher; byte[]


keyAsBytes;

31 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

private String myEncryptionKey; private


String myEncryptionScheme; SecretKey
key;

static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


public DES() throws Exception {

// TODO code application logic here myEncryptionKey

= "ThisIsSecretEncryptionKey"; myEncryptionScheme =
DESEDE_ENCRYPTION_SCHEME; keyAsBytes =

myEncryptionKey.getBytes(UNICODE_FORMAT); myKeySpec

32 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

= new DESedeKeySpec(keyAsBytes);

mySecretKeyFactory = SecretKeyFactory.getInstance(myEncryptionScheme); cipher =

Cipher.getInstance(myEncryptionScheme);

key = mySecretKeyFactory.generateSecret(myKeySpec);

public String encrypt(String unencryptedString)

{ String encryptedString = null;

try {

cipher.init(Cipher.ENCRYPT_MODE, key);

byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT); byte[]


encryptedText = cipher.doFinal(plainText);

BASE64Encoder base64encoder = new BASE64Encoder(); encryptedString =


base64encoder.encode(encryptedText); }

catch (Exception e) {
e.printStackTrace(); }
returnencryptedString; }

public String decrypt(String encryptedString)

{ String decryptedText=null;

try {

cipher.init(Cipher.DECRYPT_MODE, key);

33 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

BASE64Decoder base64decoder = new BASE64Decoder(); byte[]


encryptedText = base64decoder.decodeBuffer(encryptedString); byte[] plainText
= cipher.doFinal(encryptedText); decryptedText= bytes2String(plainText); }

catch (Exception e) {
e.printStackTrace(); }
returndecryptedText; }

private static String bytes2String(byte[] bytes)

{ StringBufferstringBuffer = new StringBuffer();

for (int i = 0; i <bytes.length;

34 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

i++) { stringBuffer.append((char) bytes[i]); }


returnstringBuffer.toString(); }

public static void main(String args []) throws Exception

{ System.out.print("Enter the string: ");


DES myEncryptor= new DES();

String stringToEncrypt = br.readLine();

String encrypted = myEncryptor.encrypt(stringToEncrypt); String decrypted =


myEncryptor.decrypt(encrypted); System.out.println("\nString To Encrypt: "

+stringToEncrypt); System.out.println("\nEncrypted Value : " +encrypted);


System.out.println("\nDecrypted Value : " +decrypted); System.out.println("");

OUTPUT:
Enter the string: Welcome String To
Encrypt: Welcome

Encrypted Value : BPQMwc0wKvg=


Decrypted Value : Welcome

35 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

5. Program to implement BlowFish algorithm logic

AIM: Write a C/JAVA program to implement the BlowFish algorithm logic.

PROGRAM:
import java.io.*;

import java.io.FileInputStream; import


java.io.FileOutputStream; import
java.security.Key;

import javax.crypto.Cipher;

import javax.crypto.CipherOutputStream; import


javax.crypto.KeyGenerator;

import sun.misc.BASE64Encoder; public


class BlowFish {

public static void main(String[] args) throws Exception {

// TODO code application logic here KeyGeneratorkeyGenerator


= KeyGenerator.getInstance("Blowfish"); keyGenerator.init(128); Key
secretKey = keyGenerator.generateKey();

Cipher cipherOut = Cipher.getInstance("Blowfish/CFB/NoPadding");


cipherOut.init(Cipher.ENCRYPT_MODE, secretKey); BASE64Encoder
encoder = new BASE64Encoder();

byte iv[] = cipherOut.getIV(); if


(iv != null) {

36 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

System.out.println("Initialization Vector of the Cipher: " + encoder.encode(iv)); }

FileInputStream fin = new FileInputStream("inputFile.txt");


FileOutputStreamfout = new FileOutputStream("outputFile.txt");
CipherOutputStreamcout = new CipherOutputStream(fout, cipherOut); int input
= 0;

while ((input = fin.read()) != -1) {

37 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

fin.close(); cout.close(); } }

OUTPUT:
Initialization Vector of the Cipher: dI1MXzW97oQ=
Contents of inputFile.txt: Hello World

Contents of outputFile.txt: ùJÖ˜ NåI“

38 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

6. Program to implement Rijndael algorithm logic

AIM: Write a C/JAVA program to implement the Rijndael algorithm logic.

PROGRAM:
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;

public class AES {

public static String asHex (byte buf[]) {


StringBuffer strbuf = new StringBuffer(buf.length *
2); int i;

for (i = 0; i < buf.length; i++)


{ if (((int) buf[i] & 0xff) < 0x10)
strbuf.append("0");

strbuf.append(Long.toString((int) buf[i] & 0xff, 16)); }


return strbuf.toString(); }

public static void main(String[] args) throws Exception

{ String message="AES still rocks!!";

// Get the KeyGenerator

KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); //


192 and 256 bits may not be available

39 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

// Generate the secret key specs. SecretKey

skey = kgen.generateKey(); byte[] raw =


skey.getEncoded();

SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");

// Instantiate the cipher

Cipher cipher = Cipher.getInstance("AES");


cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

byte[] encrypted = cipher.doFinal((args.length == 0 ? message :

40 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

args[0]).getBytes()); System.out.println("encrypted string: " +


asHex(encrypted)); cipher.init(Cipher.DECRYPT_MODE,
skeySpec); byte[] original = cipher.doFinal(encrypted); String
originalString = new String(original);

System.out.println("Original string: " + originalString + " " + asHex(original));

OUTPUT:
Input your message: Hello KGRCET
Encrypted text: 3ooo&&(*&*4r4
Decrypted text: Hello KGRCET

41 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

7. Encrypt a string using BlowFish algorithm

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 {

public static void main(String[] args) throws Exception {

// create a key generator based upon the Blowfish cipher


KeyGeneratorkeygenerator = KeyGenerator.getInstance("Blowfish");

// create a key

// 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

42 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

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

43 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

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

44 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

8. RSA Algorithm

AIM: Write a Java program to implement RSA Algoithm.

PROGRAM:
import java.io.BufferedReader; import
java.io.InputStreamReader; import
java.math.*;

import java.util.Random; import


java.util.Scanner; public class
RSA {

static Scanner sc = new Scanner(System.in); public


static void main(String[] args) {

// TODO code application logic here


System.out.print("Enter a Prime number: ");

BigInteger p = sc.nextBigInteger(); // Here's one prime number..


System.out.print("Enter another prime number: "); BigInteger q =
sc.nextBigInteger(); // ..and another.

BigInteger n = p.multiply(q);

BigInteger n2 = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));

BigInteger e = generateE(n2);

BigInteger d = e.modInverse(n2); // Here's the multiplicative inverse

45 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

System.out.println("Encryption keys are: " + e + ", " + n);


System.out.println("Decryption keys are: " + d + ", " + n);

public static BigIntegergenerateE(BigIntegerfiofn) { int y,


intGCD;

BigInteger e; BigInteger
gcd;

Random x = new Random();

do {

46 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

y = x.nextInt(fiofn.intValue()-1);
String z = Integer.toString(y);

e = new BigInteger(z); gcd =


fiofn.gcd(e);

intGCD = gcd.intValue();

while(y <= 2 || intGCD != 1); return


e;

OUTPUT:

Enter a Prime number: 5

Enter another prime number: 11


Encryption keys are: 33, 55

Decryption keys are: 17, 55

47 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

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;

import java.security.KeyPairGenerator; import


java.security.SecureRandom; import
javax.crypto.spec.DHParameterSpec; import
javax.crypto.spec.DHPublicKeySpec; 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));

48 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

BigIntegerXb = new BigInteger(Integer.toString(XbValue));


createKey(); intbitLength = 512; // 512 bits

SecureRandomrnd = new SecureRandom();

p = BigInteger.probablePrime(bitLength, rnd); g =
BigInteger.probablePrime(bitLength, rnd);

49 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

createSpecificKey(p, g);

public static void createKey() throws Exception {

KeyPairGeneratorkpg = KeyPairGenerator.getInstance("DiffieHellman");
kpg.initialize(512);

KeyPairkp = kpg.generateKeyPair();

KeyFactorykfactory = KeyFactory.getInstance("DiffieHellman"); DHPublicKeySpeckspec


= (DHPublicKeySpec) kfactory.getKeySpec(kp.getPublic(), DHPublicKeySpec.class);

System.out.println("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


= (DHPublicKeySpec) kfactory.getKeySpec(kp.getPublic(), DHPublicKeySpec.class);

System.out.println("\nPublic key is : " +kspec);

50 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

OUTPUT:
Public key is: javax.crypto.spec.DHPublicKeySpec@5afd29 Public
key is: javax.crypto.spec.DHPublicKeySpec@9971ad

51 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

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 {

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.println(" ToString = " +md.toString());

String input = "";


md.update(input.getBytes()); byte[]
output = md.digest();
System.out.println();

System.out.println("SHA1(\""+input+"\") = " +bytesToHex(output));

input = "abc";
md.update(input.getBytes()); output =
md.digest(); System.out.println();

System.out.println("SHA1(\""+input+"\") = " +bytesToHex(output));

52 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());

output = md.digest();
System.out.println();

System.out.println("SHA1(\"" +input+"\") = " +bytesToHex(output)); System.out.println(""); }

catch (Exception e) {

53 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

System.out.println("Exception: " +e);

public static String bytesToHex(byte[] b) {

char hexDigit[] = {'0', '1', '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) & 0x0f]); buf.append(hexDigit[b[j] & 0x0f]); }
returnbuf.toString(); }

OUTPUT:
Message digest object info:
Algorithm = SHA1

Provider = SUN version 1.6

ToString = SHA1 Message Digest from SUN, <initialized> SHA1("") =


DA39A3EE5E6B4B0D3255BFEF95601890AFD80709 SHA1("abc") =
A9993E364706816ABA3E25717850C26C9CD0D89D

SHA1("abcdefghijklmnopqrstuvwxyz")=32D10C7B8CF96570CA04CE37F2A19D8424 0D3A89

54 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

11. Message Digest Algorithm5 (MD5)


AIM: Calculate the message digest of a text using the SHA-1 algorithm in JAVA.

PROGRAM:
import java.security.*; public
class MD5 {

public static void main(String[] a) {

// TODO code application logic here

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());

String input = "";

md.update(input.getBytes());

byte[] output = md.digest();


System.out.println();

System.out.println("MD5(\""+input+"\") = " +bytesToHex(output));

input = "abc";
md.update(input.getBytes()); output =
md.digest(); System.out.println();

55 COMPUTER SCIENCE & ENGINEERING


CRYPTOGRAPHY & NETWORK SECURITY LAB

System.out.println("MD5(\""+input+"\") = " +bytesToHex(output));

input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());

output = md.digest();
System.out.println();

System.out.println("MD5(\"" +input+"\") = "

+bytesToHex(output)); System.out.println("");

56 COMPUTER SCIENCE & ENGINEERING


catch (Exception e) {
CRYPTOGRAPHY & NETWORK SECURITY LAB
System.out.println("Exception: " +e); }

public static String bytesToHex(byte[] b) {

char hexDigit[] = {'0', '1', '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) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]); }

return buf.toString(); } }

OUTPUT:
Message digest object
info: Algorithm = MD5

Provider = SUN version 1.6

ToString = MD5 Message Digest from SUN, <initialized> MD5("") =


D41D8CD98F00B204E9800998ECF8427E MD5("abc") =

900150983CD24FB0D6963F7D28E17F72 MD5("abcdefghijklmnopqrstuvwxyz") =
C3FCD3D76192E4007DFB496CCA67E13B

57 COMPUTER SCIENCE & ENGINEERING


Nominal roll s

CRYPTOGRAPHY & NETWORK SECURITY LAB


S.N
Roll No Name of the Candidate
o

21J41A62D1 ADUMEKALA SHIVA KUMAR


1
21J41A62D2 AENUGULA SAI MANOHAR
2
21J41A62D3 ARRAM SAI LAXMI PRASANNA
3
21J41A62D4 AVATURI NAGA SAI AMEYA
4
21J41A62D5 BADAVATH KALYANI
5
21J41A62D6 BAIROJU SHIVANI
6
21J41A62D7 BATTU SRINIVAS
7
21J41A62D8 BATTULA JAYANTH KUMAR
8
21J41A62D9 BHUKYA NITHISH KUMAR
9
21J41A62E0 BIRAVALLI NIRMAL KUMAR
10
21J41A62E1 BUCHHAIAHGARI ABHINAY REDDY
11
21J41A62E2 BYSANI MANAHOR KUMAR
12
21J41A62E3 CHEKILAM SAL KRISHNA
13
21J41A62E4 CHILAKAPATI NAGARAJU
14
21J41A62E5 DIGGIREDDY SAI PRAANAVI SNEHA REDDY
15
21J41A62E6 DUSTHAKAR PAVAN KUMAR
16
21J41A62E7 EEGA SAKETH REDDY
17
21J41A62E8 ELANKI SHRAVAN KUMAR REDDY
18
21J41A62E9 ELURI SIDDHARTHA CHOWDARY
19
21J41A62F0 GAMPA HARISH
20
21J41A62F1 GANTALA AVINASH
21
21J41A62F2 GANTHALA TARUN
22
21J41A62F3 GOLLAPALLI SAHITHI 58 COMPUTER SCIENCE & ENGINEERING
23
21J41A62F4 GUNDEPAKA PRADEEP
24
21J41A62F5 JUPALLI VIVEK
25 CRYPTOGRAPHY & NETWORK SECURITY LAB
21J41A62F6 K ANIL
26
21J41A62F7 K TIRUMALA SREEKAR RAO
27
21J41A62F9 KANAPURAM HARI KRISHNA
28
21J41A62G0 KARANGULA SAMUEL JAYANTH
29
21J41A62G1 KATTAMURI VENKATA AKSHITHA
30
21J41A62G2 KONDAM YASHWANTH
31
21J41A62G3 KYASA KAVERI
32
21J41A62G4 LAVUDIYA DATHAPRASAD
33
21J41A62G5 LINGAREDDY POOJWALA
34
21J41A62G6 M PRANATHI
35
21J41A62G7 MALE SAIGANESH GOUD
36
21J41A62G9 MANOJU VILAS
37
21J41A62H0 MOHAMMAD SAIFUDDIN
38
21J41A62H1 MOLUGURI ANIRUD
39
21J41A62H2 MUDAVATH VENKATESH
40
21J41A62H3 MURIKINTI VYSHNAVI
41
21J41A62H4 NALLAVELLY LALITH REDDY
42
21J41A62H5 NUNUGONDA HANSIKA
43
21J41A62H6 PATTIPAKALA ROHAN
44
21J41A62H7 PULLAGURLA RAGHU
45
21J41A62H8 PUNUGOTI AKSHITHA
46
21J41A62H9 RAJOLI MOUNIKA
47
21J41A62J0 REPAKULA GANESH
48
21J41A62J1 S GYANJOTH SINGH
49
21J41A62J2 S SAI VINODH 59 COMPUTER SCIENCE & ENGINEERING
50
51 21J41A62J3 S VIJAY KUMAR
21J41A62J4 SANTI VIDHATHA
52 CRYPTOGRAPHY & NETWORK SECURITY LAB
21J41A62J5 SARA PRANEETH
53
21J41A62J6 SEELAM CHARANDEEP REDDY
54
21J41A62J8 SUKKA MANIKIRAN
55
21J41A62J9 THOLLAMADUGU SIVA KUMAR REDDY
56
21J41A62K0 UJWALA SAI PUVVULA
57
21J41A62K1 VEERAVALLI DHARMA TEJA
58
21J41A62K2 V ESWAR REDDY
59
21J41A62K3 VATTIPALLY SHASHANK
60
21J41A62K4 VEDULLA ANJANA
61
22J45A6213 KAMISETTI SAI TEJA
62
22J45A6214 AMBIDI SRICHARAN
63
22J45A6215 PERUKA SAI SRIHAN
64
22J45A6216 PERUMANDLA GANESH
65
22J45A6217 BHUKYA SOUNDARYA
66
22J45A6218 RATHLAVATH RAMESH NAYAK
67
22J45A6219 PABBATI BHAVANA
68
22J45A6220 MUSIDIPALLI NAVEEN KUMAR
69
20J41A6235 MM HUSSAIN
70
20J41A6256 M.SAHITH
71

60 COMPUTER SCIENCE & ENGINEERING

You might also like