Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
- def encrypt(original_text, shift_amount):
- original_text=original_text.lower()
- deco=""
- for letter in original_text:
- if letter not in alphabet:
- deco+=letter
- else:
- deco+= alphabet[(alphabet.index(letter) + shift_amount) % len(alphabet)]
- print(deco)
- def decrypt(mensaje,salt):
- deco = ""
- for letter in mensaje:
- if letter not in alphabet:
- deco += letter
- elif (alphabet.index(letter) - salt) < 0:
- deco += alphabet[(alphabet.index(letter) - salt) + len(alphabet)]
- else:
- deco += alphabet[(alphabet.index(letter) - salt)]
- print(deco)
- def caesar(direction):
- if direction == 'e':
- text = input("Type your message:\n").lower()
- shift = int(input("Type the shift number:\n"))
- encrypt(text, shift)
- else:
- text = input("Type your message:\n").lower()
- shift = int(input("Type the shift number:\n"))
- decrypt(text, shift)
- u_choice = 'x'
- while u_choice != 'e' and u_choice != 'd' :
- u_choice = input("Pulse 'd' para desencriptar o 'e' para encriptar: ").lower()
- if u_choice == 'e' or u_choice == 'd':
- caesar(u_choice)
- option=input("¿Quiere más? (y/n): ").lower()
- if option == 'y':
- u_choice='x'
- else:
- print("Opción incorrecta")
Advertisement
Add Comment
Please, Sign In to add comment