cesar.py 458 B

123456789101112131415161718192021
  1. def cesar_cipher(text, key=3):
  2. result = ""
  3. i = 0
  4. while i < len(text):
  5. char = text[i]
  6. if char.isupper():
  7. result += chr((ord(char) - 65 + key) % 26 + 65)
  8. else:
  9. result += chr((ord(char) - 97 + key) % 26 + 97)
  10. i += 1
  11. return result
  12. # Chiamata della funzione utilizzando keyword arguments
  13. text = "Inserisci il testo da cifrare"
  14. key = 3
  15. print("Testo cifrato: ", cesar_cipher(text=text))