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()
En esta página del sitio puede ver el video en línea 103. Caesar Cipher Encryption in Python with Code de Duración hora minuto segunda en buena calidad , que subió el usuario Ram Case 22 septiembre 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 24 veces y le gustó 0 a los espectadores. Disfruta viendo!