Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
400 B
1
Indexable
Never
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))
Leave a Comment