0% found this document useful (0 votes)
9 views7 pages

Bda Megh

The document certifies that Mr. Rupapara Purvesh has successfully completed laboratory experiments in Information and Network Security during the academic year 2024-25. It includes a table of contents listing various encryption-decryption experiments, such as Caesar cipher and RSA algorithm. Additionally, a detailed implementation of the Playfair cipher encryption-decryption process is provided, including code examples.

Uploaded by

Purvesh Rupapara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Bda Megh

The document certifies that Mr. Rupapara Purvesh has successfully completed laboratory experiments in Information and Network Security during the academic year 2024-25. It includes a table of contents listing various encryption-decryption experiments, such as Caesar cipher and RSA algorithm. Additionally, a detailed implementation of the Playfair cipher encryption-decryption process is provided, including code examples.

Uploaded by

Purvesh Rupapara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

FACULTY OF ENGINEERING AND TECHNOLOGY

BACHELOR OF TECHNOLOGY

Information and Network Security Laboratory


(203105311)

SEMESTER VII
Information Technology
Department
CERTIFICATE
This is to certify that

Mr. Rupapara with enrolment no. 22030310870 has


Purvesh
successfully completed his/her laboratory experiments in the

InformationAnd Network Security(203105311)from the


department of
InformationTechnology
during the academic year 2024-25.

Date of Submission: .................. Staff in charge …………….

Head Of Department: …………


TABLE OF CONTENTS

SR.NO Experiment Title Page No Date of Date of Marks Sign


Performance Submission

From To

1. Implement Caesar cipher encryption-


decryption

2. Implement Monoalphabetic cipher


encryption-decryption

3. Implement Playfair cipher


encryption-decryption

4. Implement Polyalphabetic
cipher encryption-decryption

5. Implement Hill cipher encryption-


decryption

6. Implement Simple Transposition


encryption-decryption

7. Implement One time pad encryption-


decryption

8. Implement Diffi-Hellmen key


exchange Method

9. Implement RSA
encryption- decryption
algorithm
10. Demonstrate working of Digital
Signature using Cryptool
Faculty of Engineering & Technology

Subject: INS LAB


Subject-Code:203105311
B.Tech. IT Year 4th Semester: 7th

Practical: 3

Aim: Implement Playfair cipher encryption-decryption.

The Playfair cipher is a manual symmetric encryption technique and was the first digraph
substitution cipher. It encrypts pairs of letters (digraphs), making it more secure than simple
substitution ciphers.

Program :

import re

def preprocess_message(message): message =


re.sub(r'[^A-Z]', '', message.upper()) message
= message.replace('J', 'I')
return message

def generate_playfair_matrix(key):
key = preprocess_message(key +
'ABCDEFGHIKLMNOPQRSTUVWXYZ') matrix = [] for char in key:
if char not in matrix:
matrix.append(char)
return matrix

def find_position(matrix, char):

index = matrix.index(char) return


(index // 5, index % 5)

def encrypt(message, key):


message =
preprocess_message(message) matrix =
generate_playfair_matrix(key)
encrypted_text = []

i = 0 while i <
len(message):
if i == len(message) - 1:

Name : Mihir Karena 5|Page


Enrollment No.: - 2203031087009
Faculty of Engineering & Technology

Subject: INS LAB


Subject-Code:203105311
B.Tech. IT Year 4th Semester: 7th
message += 'X'
if message[i] == message[i + 1]: message =
message[:i + 1] + 'X' + message[i + 1:] pair1
= message[i] pair2 = message[i + 1]
row1, col1 = find_position(matrix, pair1) row2,
col2 = find_position(matrix, pair2) if row1 ==
row2: encrypted_text.append(matrix[row1 * 5 +
(col1 + 1) % 5])
encrypted_text.append(matrix[row2 * 5 + (col2 +
1) % 5])
elif col1 == col2: encrypted_text.append(matrix[((row1 + 1)
% 5) * 5 + col1]) encrypted_text.append(matrix[((row2 +
1) % 5) * 5 + col2])
else:
encrypted_text.append(matrix[row1 * 5 + col2])
encrypted_text.append(matrix[row2 * 5 + col1])
i += 2
return ''.join(encrypted_text)

def decrypt(ciphertext, key): matrix =


generate_playfair_matrix(key) decrypted_text = [] i = 0 while
i < len(ciphertext): pair1 = ciphertext[i] pair2 = ciphertext[i +
1] row1, col1 = find_position(matrix, pair1) row2, col2 =
find_position(matrix, pair2) if row1 == row2:
decrypted_text.append(matrix[row1 * 5 + (col1 - 1) % 5])
decrypted_text.append(matrix[row2 * 5 + (col2 - 1) % 5])
elif col1 == col2:
decrypted_text.append(matrix[((row1 - 1) % 5) * 5 + col1])
decrypted_text.append(matrix[((row2 - 1) % 5) * 5 + col2])
else:
decrypted_text.append(matrix[row1 * 5 + col2])
decrypted_text.append(matrix[row2 * 5 + col1])
i += 2

if decrypted_text[-1] == 'X':
decrypted_text = decrypted_text[:-1]
return ''.join(decrypted_text)

key = input ("Enter key:") message


= input ("Enter Plain text:")
Name : Mihir Karena 6|Page
Enrollment No.: - 2203031087009
Faculty of Engineering & Technology

Subject: INS LAB


Subject-Code:203105311
B.Tech. IT Year 4th Semester: 7th
encrypted_message =
encrypt(message, key)
decrypted_message = decrypt(encrypted_message, key)

print(f"Original Message: {message}")


print(f"Encrypted Message:
{encrypted_message}") print(f"Decrypted
Message: {decrypted_message}")

Output :

Name : Mihir Karena 7|Page


Enrollment No.: - 2203031087009

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy