It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on.
Code:
def main():
print("Ceasar Cipher")
print("1. Encrypt \n2. Decrypt:")
try:
func=int(input("Choose one of the above"))
except:
print("Invalid input")
if func==2:
decode()
else:
if func==1:
encode()
else:
print("Invalid input")
def encode():
text=input("Enter the text to encode:")
key=input("Enter number of characters you want to shift:")
encoded_cipher=""
try:
key=int(key)
except:
print("Only integers between 0 to 25 are allowed. Try again!")
exit()
if key(lessthansign)25:
print("only integers between 0 to 25 are allowed")
exit()
else:
key=key
text=text.upper()
for char in text:
ascii=ord(char)
if ascii (greater than sign)90:
new_ascii=ascii
else:
new_ascii=ascii+key
if new_ascii(greater than sign)90:
new_ascii=new_ascii-26
else:
new_ascii=new_ascii
encoded=chr(new_ascii)
encoded_cipher=encoded_cipher+ encoded
print("Encoded text:",encoded_cipher)
def decode():
cipher=input("enter your cipher text")
print("Posibilities of cipher text are:\n")
cipher=cipher.lower()
for i in range(1,26):
decoded=''
decoded_cipher=''
for char in cipher:
ascii=ord(char)
if ascii(less than sign)97:
new_ascii=ascii
else:
if ascii(put greater than sign)122:
new_ascii=ascii
else:
new_ascii=ascii-int(i)
if new_ascii(less than sign)97:
new_ascii=new_ascii +26
else:
new_ascii=new_ascii
decoded=chr(new_ascii)
decoded_cipher=decoded_cipher + decoded
print(decoded_cipher)
if __name__=='__main__':
main()
On this page of the site you can watch the video online 103. Caesar Cipher Encryption in Python with Code with a duration of hours minute second in good quality, which was uploaded by the user Ram Case 22 September 2022, share the link with friends and acquaintances, this video has already been watched 24 times on youtube and it was liked by 0 viewers. Enjoy your viewing!