Untitled
unknown
plain_text
a year ago
400 B
9
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