Professional Documents
Culture Documents
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("----------------------------------------------------------------------------------------------------------------"
---------------------------------------------------------------------------------------------------------------
*****CAESAR CIPHER*****
1 for Encryption
2 for Decryption
----------------------------------------------------------------------------------------------------------------
In [ ]: