0% found this document useful (0 votes)
14 views6 pages

15-Lab4 CNS

The document describes implementing a Caesar cipher encryption and decryption program. It includes: 1. Visiting virtual lab sites on shift and substitution ciphers and taking screenshots of the simulations and assignments. 2. Writing a Python program that implements Caesar cipher encryption and decryption functions. The program contains a graphical user interface with buttons to encrypt, decrypt, and clear text as well as labels and entries for plaintext, encrypted text, and shift value.

Uploaded by

sumeet19sapkal
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)
14 views6 pages

15-Lab4 CNS

The document describes implementing a Caesar cipher encryption and decryption program. It includes: 1. Visiting virtual lab sites on shift and substitution ciphers and taking screenshots of the simulations and assignments. 2. Writing a Python program that implements Caesar cipher encryption and decryption functions. The program contains a graphical user interface with buttons to encrypt, decrypt, and clear text as well as labels and entries for plaintext, encrypted text, and shift value.

Uploaded by

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

Bansilal Ramnath Agarwal Charitable Trust’s

Vishwakarma Institute of Technology, Pune-37


(An Autonomous Institute of Savitribai Phule Pune
University)

Department of Electronics and


Telecommunication
Division D

Batch 1

GR-no 12110238

Roll no 15

Name Sumeet sapkal

CNS Lab-4

Lab 4: Implement Encryption and Decryption using Caesar CipherImplement the


following
1. Visit the following pages
a) https://cse29-iiith.vlabs.ac.in/exp/shift-cipher/
b) https://cse29-iiith.vlabs.ac.in/exp/substitution-cipher/
and implement the simulation using virtual labs. Take screen shots of simulations and
assignments given on this site and paste in word.
2. Implement CAESAR CIPHER code in python or matlab and submit the
same.
Implementation:
1.

(Simulation)
(Assignment)

2.
(Simulation)
2. Implement CEASER CIÏER code in python oí matlab and submit the same.

import tkinter as tk
from tkinter import messagebox

def caesar_cipher_encrypt(text, shift):


encrypted_text = ""
for char in text:
if char.isalpha():
is_upper = char.isupper()
char = char.lower()
encrypted_char = chr(((ord(char) - ord('a') + shift) % 26) + ord('a'))
if is_upper:
encrypted_char = encrypted_char.upper()
encrypted_text += encrypted_char
else:
encrypted_text += char
return encrypted_text

def caesar_cipher_decrypt(encrypted_text, shift):


decrypted_text = ""
for char in encrypted_text:
if char.isalpha():
is_upper = char.isupper()
char = char.lower()
decrypted_char = chr(((ord(char) - ord('a') - shift) % 26) + ord('a'))
if is_upper:
decrypted_char = decrypted_char.upper()
decrypted_text += decrypted_char
else:
decrypted_text += char
return decrypted_text

def encrypt_button_click():
plaintext =
plaintext_entry.get() shift =
int(shift_entry.get()) if 0 <=
shift <= 25:
encrypted_text = caesar_cipher_encrypt(plaintext, shift)
result_text.config(text="Encrypted: " + encrypted_text)
else:
messagebox.showerror("Error", "Shift value should be between 0 and 25")

def decrypt_button_click():
encrypted_text = encrypted_entry.get()
shift = int(shift_entry.get())
if 0 <= shift <= 25:
decrypted_text = caesar_cipher_decrypt(encrypted_text,
shift) result_text.config(text="Decrypted: " +
decrypted_text) else:
messagebox.showerror("Error", "Shift value should be between 0 and 25")

def clear_button_click():
plaintext_entry.delete(0, 'end')
encrypted_entry.delete(0, 'end')
shift_entry.delete(0, 'end')
result_text.config(text="")

# Create the main window


window = tk.Tk()
window.title("Caesar Cipher")

# Create and arrange widgets


plaintext_label = tk.Label(window, text="Enter Text:")
plaintext_label.pack()
plaintext_entry = tk.Entry(window)
plaintext_entry.pack()

shift_label = tk.Label(window, text="Enter Shift Value (0-25):")


shift_label.pack()
shift_entry = tk.Entry(window)
shift_entry.pack()

encrypt_button = tk.Button(window,
text="Encrypt", command=encrypt_button_click)
encrypt_button.pack()
decrypt_button = tk.Button(window,
text="Decrypt", command=decrypt_button_click)
decrypt_button.pack()
clear_button = tk.Button(window,
text="Clear", command=clear_button_click)
clear_button.pack()

result_text = tk.Label(window, text="", wraplength=400)


result_text.pack()

encrypted_label = tk.Label(window, text="Enter Encrypted Text:")


encrypted_label.pack()
encrypted_entry = tk.Entry(window)
encrypted_entry.pack()

window.mainloop()

Output :

You might also like