0% found this document useful (0 votes)
12 views2 pages

Ex 2 Cns - 1022

The document outlines an exercise to implement the Caesar cipher, a simple encryption method used by Julius Caesar. It describes the process of shifting letters in the alphabet and provides a Python program to encrypt and decrypt messages. The program successfully demonstrates the encryption of 'HELLO, WORLD!' to 'KHOOR, ZRUOG!' and back to the original message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Ex 2 Cns - 1022

The document outlines an exercise to implement the Caesar cipher, a simple encryption method used by Julius Caesar. It describes the process of shifting letters in the alphabet and provides a Python program to encrypt and decrypt messages. The program successfully demonstrates the encryption of 'HELLO, WORLD!' to 'KHOOR, ZRUOG!' and back to the original message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

23DC2055 – Cryptography and Network Security lab URK22AI1022

Implement Substitution Cipher


Ex. No. 2
Date of Exercise 09.01.2025

Aim:

To implement Caesar cipher and prove its cryptography.

Description:
The Caesar Cipher is one of the simplest and oldest methods of encrypting messages, named
after Julius Caesar, who reportedly used it to protect his military communications. This technique
involves shifting the letters of the alphabet by a fixed number of places. For example, with a shift
of three, the letter ‘A’ becomes ‘D’, ‘B’ becomes ‘E’, and so on. Despite its simplicity, the Caesar
Cipher formed the groundwork for modern cryptographic techniques. In this article, we’ll explore
how the Caesar Cipher works, its significance, and its impact on the development of cryptography
with its advantages and disadvantages.
Program:
def caesar_cipher(text,shift,mode="encrypt"):
result=""
if mode=="decrypt":
shift=-shift
for char in text:
if char.isalpha():
ascil_offset=65 if char.isupper() else 97
shifted_char=chr(((ord(char) - ascil_offset+ shift) %26) + ascil_offset)
result+= shifted_char
else:
result+= char
return result
message="HELLO, WORLD!"
shift_value=3

encrypted_message=caesar_cipher(message,shift_value,mode="encrypt")
print("Encrypted:",encrypted_message)
1
23DC2055 – Cryptography and Network Security lab URK22AI1022

decrypted_message=caesar_cipher(encrypted_message, shift_value,mode="decrypt")
print("Decrypted:",decrypted_message)

Output
Encrypted: KHOOR, ZRUOG!
Decrypted: HELLO, WORLD!

Result
The above programs are verified and executed successfully.

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