fork download
  1. def caesar_encrypt(text, shift):
  2. result = ""
  3. for char in text:
  4. if char.isalpha():
  5. shift_base = 65 if char.isupper() else 97
  6. result += chr((ord(char) - shift_base + shift) % 26 + shift_base)
  7. else:
  8. result += char
  9. return result
  10.  
  11. text = "Praktikum Keamanan Komputer"
  12. shift = 3
  13. print("Hasil Enkripsi Caesar Cipher:", caesar_encrypt(text, shift))
Success #stdin #stdout 0.02s 7272KB
stdin
Standard input is empty
stdout
('Hasil Enkripsi Caesar Cipher:', 'Sudnwlnxp Nhdpdqdq Nrpsxwhu')