0% found this document useful (0 votes)
22 views4 pages

INS Manual

The document outlines practical exercises for implementing Caesar and Monoalphabetic ciphers for encryption and decryption. It details the processes for both ciphers, including the programming logic and sample code for each. The conclusions highlight the simplicity of the Caesar cipher and the stronger security of the Monoalphabetic cipher compared to the former.

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)
22 views4 pages

INS Manual

The document outlines practical exercises for implementing Caesar and Monoalphabetic ciphers for encryption and decryption. It details the processes for both ciphers, including the programming logic and sample code for each. The conclusions highlight the simplicity of the Caesar cipher and the stronger security of the Monoalphabetic cipher compared to the former.

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

Faculty of Engineering & Technology

Subject Name: - INS LAB


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

Practical – 1
Aim: Implement Caesar Cipher Encryption and Decryption.

• A Caesar cipher, also known as a shift cipher, is a type of substitution cipher where
each letter in the plaintext is shifted a certain number of places down or up the
alphabet.
• Encryption Process:

• Choose a shift value (key), typically between 1 and 25. For example, if the shift
value is 3, then each letter in the plaintext is replaced by the letter three positions
to the right in the alphabet.
• The alphabet is wrapped around; so after 'Z', it goes back to 'A'. For instance, with
a shift of 3, 'A' becomes 'D', 'B' becomes 'E', and 'Z' becomes 'C'.

• Decryption Process:

• To decrypt, you simply shift the letters back by the same amount. For a shift of 3,
'D' becomes 'A', 'E' becomes 'B', and 'C' becomes 'Z'.

Program: def

caesar_cipher(text, shift):

result = " "

for char in text:

if char.isalpha(): # Check if the character is a letter

shift_base = ord('A') if char.isupper() else ord('a')

result += chr((ord(char) - shift_base + shift) % 26 + shift_base)

else:

result += char return result def

main(): text = input("Enter the message: ")

shift = int(input("Enter the shift number: "))

encrypted_text = caesar_cipher(text, shift)

Enrollment No: 210303108210 Page | 1


Faculty of Engineering & Technology
Subject Name: - INS LAB
Subject Code: - 203105311
B.Tech.-IT Year-4th Semester: - 7th

decrypted_text =

caesar_cipher(encrypted_text, -shift)

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

print(f"Encrypted Message: {encrypted_text}")

print(f"Decrypted Message: {decrypted_text}")

if __name__ == "__main__":
main() Output:

Conclusion: The Caesar cipher shifts each letter in the plaintext by a


predetermine number of positions in the alphabet. The Caesar Cipher technique
is one of the earliest and simplest methods of encryption technique.

Enrollment No: 210303108210 Page | 2


Faculty of Engineering & Technology
Subject Name: - INS LAB
Subject Code: - 203105311
B.Tech.-IT Year-4th Semester: - 7th

Practical – 2
Aim: Implement Monoalphabetic Cipher Encryption and
Decryption.
• Monoalphabetic cipher is a substitution technique where each letter in the plaintext
is replaced by fixed letter of the alphabet.
• Monoalphabetic ciphers would include the Caesar-shift cipher.
• The relationship between a character in the plain text and the characters in the
cipher text is one-to-one.
• In monoalphabetic cipher the value of key does not depend on the position of the
plain text character in the plain text stream.

Program: def

create_substitution_dict(key):

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
return {alphabet[i]: key[i] for i in range(len(alphabet))}

def encrypt(plaintext, key): plaintext = plaintext.upper()

substitution_dict = create_substitution_dict(key) ciphertext =

''.join([substitution_dict.get(char, char) for char in plaintext]) return

ciphertext

def decrypt(ciphertext, key): ciphertext = ciphertext.upper()

substitution_dict = create_substitution_dict(key) reversed_dict = {v: k

for k, v in substitution_dict.items()} plaintext =

''.join([reversed_dict.get(char, char) for char in ciphertext]) return

plaintext

Enrollment No: 210303108210 Page | 3


Faculty of Engineering & Technology
Subject Name: - INS LAB
Subject Code: - 203105311
B.Tech.-IT Year-4th Semester: - 7th

key = input("Enter a key:")


plaintext = input("Enter Plaintext:") ciphertext

= encrypt(plaintext, key) decrypted_text =

decrypt(ciphertext, key)

print(f"Key: {key}") print(f"Plaintext:

{plaintext}") print(f"Ciphertext:

{ciphertext}") print(f"Decrypted Text:

{decrypted_text}") Output:

Conclusion: Monoalphabetic cipher is simple and easy to understand substitution


cipher. 26! Possibility is possible in monoalphabetic cipher. Monoalphabetic is
stronger than caesar cipher and less stronger than polyalphabetic cipher.

Enrollment No: 210303108210 Page | 4

You might also like