CESAR ALGORITHM
34 0H0DKA90,
F34E 4E 74FF70 BAEF 09ZDKBF0. I4F3 Z0EXD X72AD4F38:
#/usr/bin/python3
def Cesar(mensaje, clave, modo):
alfabeto = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789'
resultado = ''
# el mensaje se pasa a mayusculas
mensaje = mensaje.upper()
# cifra o descifra cada caracter del mensaje
for caracter in mensaje:
if caracter in alfabeto:
# calcula el numero correspondiente al caracter
num = alfabeto.find(caracter)
if modo == 'Encrypt':
num = (num + clave) % len(alfabeto)
elif modo == 'Decrypt':
num = (num - clave) % len(alfabeto)
# lo añade al resultado
resultado = resultado + alfabeto[num]
else:
# si no está en el alfabeto no se modifica
resultado = resultado + caracter
print(resultado)
#######
#MAIN Cipher cesar algorithm
########
while True:
operation=input(str("Operation type : Encrypt/Decrypt "))
if operation =='Encrypt':
message = input(str("Message to encrypt : "))
key = input(str("key number from 1 to 24 : "))
elif operation == 'Decrypt':
message = input(str("Message to encrypt : "))
key = input(str("key number from 1 to 24 : "))
Cesar(message,int(key),operation)
Solution:

No comments:
Post a Comment