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

Pro

The document outlines a Python program that implements the Caesar Cipher algorithm for encrypting and decrypting text. It includes functions for both encryption and decryption, allowing users to input a message and a shift value. The program processes the message character by character, handling both uppercase and lowercase letters while preserving spaces.

Uploaded by

Suthram Raghu
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)
6 views2 pages

Pro

The document outlines a Python program that implements the Caesar Cipher algorithm for encrypting and decrypting text. It includes functions for both encryption and decryption, allowing users to input a message and a shift value. The program processes the message character by character, handling both uppercase and lowercase letters while preserving spaces.

Uploaded by

Suthram Raghu
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

'''

Task-01

Implement Caesar Cipher

Create a Python program that can encrypt and decrypt text using the Caesar Cipher algorithm.

Allow users to input a message and a shift value to perform encryption and decryption.

'''

#Encryption Function

def Encryption(message,shift):

result = ""

# perform the iteratation on the given mesasge

for i in range(len(message)):

char = message[i]

# Check when there is space in message, and then add it.

if char==" ":

result+=" "

# check if a character is uppercase then encrypt it according to uppercase character

elif (char.isupper()):

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

# check if a character is lowercase then encrypt it according to lowercase character

else:

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

return result

#Decryption Function

def Decryption(message,shift):

return Encryption(message, -shift)


#main function

message = input("Enter the message to encrypt: ")

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

encrypted_message = Encryption(message, shift)

decrypted_message = Decryption(encrypted_message, shift)

print("\nEncrypted message:", encrypted_message)

print("\nDecrypted message:", decrypted_message)

print("\n\n")

You might also like