You are on page 1of 2

1/12/22, 8:57 PM Caesar Cipher - Jupyter Notebook

In [2]: print("---------------------------------------------------------------------------------------------------------------")
print(" *****CAESAR CIPHER***** ")

print("Enter your choice \n1 for Encryption \n2 for Decryption")
x=int(input())

if x==1:
txt = input("Enter the text: ")
key = int(input("Enter the key: "))
def Encrypt_func(txt, key):
result = ""
for i in range(len(txt)):
char = txt[i]
if (char.isupper()):
result += chr((ord(char)+ key - 65) % 26 + 65)
else:
result += chr((ord(char)+ key - 97) % 26 + 97)
return result
print("Plain text : ", txt)
print("Cipher text :", Encrypt_func(txt, key))

elif x==2:
txt = input("Enter the text: ")
key = int(input("Enter the key: "))
def Decrypt_func(txt, key):
result = ""
for i in range(len(txt)):
char = txt[i]
if (char.isupper()):
result += chr((ord(char)+ key - 65) % 26 + 65)
else:
result += chr((ord(char)+ key - 97) % 26 + 97)
return result
print("Plain text : ", txt)
print("Cipher text :", Decrypt_func(txt, key))

else:
print("You have entered the Wrong Choice !\nTRY AGAIN")

print("----------------------------------------------------------------------------------------------------------------"

localhost:8888/notebooks/Untitled Folder/Caesar Cipher.ipynb# 2/3


1/12/22, 8:57 PM Caesar Cipher - Jupyter Notebook

---------------------------------------------------------------------------------------------------------------

*****CAESAR CIPHER*****

Enter your choice

1 for Encryption

2 for Decryption

Enter the text: Abd

Enter the key: 3

Plain text : Abd

Cipher text : Deg

----------------------------------------------------------------------------------------------------------------

In [ ]: ​

localhost:8888/notebooks/Untitled Folder/Caesar Cipher.ipynb# 3/3

You might also like