Untitled
Anonymous
plain_text
09/11/2024 9:52 AM
536 B
16
Indexable
def caesar_cipher(text, shift):
result = ""
for char in text:
if char.isalpha():
shift_base = ord('A') if char.isupper() else ord('a')
result += chr((ord(char) - shift_base + shift) % 26 + shift_base)
else:
result += char
return result
# Contoh penggunaan
text = "HELLO WORLD"
shift = 3
print(caesar_cipher(text, shift))
Editor is loading...
Leave a Comment