Enter your text, adjust the shift, and see the encryption process in action.
Examples of Caesar Cipher implementation in various programming languages.
def caesar_cipher(text, shift, encrypt=True):
result = ""
for char in text:
if char.isalpha():
ascii_offset = 65 if char.isupper() else 97
shifted = (ord(char) - ascii_offset + (shift if encrypt else -shift)) % 26
result += chr(shifted + ascii_offset)
else:
result += char
return result
# Example usage
plaintext = "HELLO WORLD"
shift = 3
encrypted = caesar_cipher(plaintext, shift)
decrypted = caesar_cipher(encrypted, shift, encrypt=False)
print(f"Encrypted: {encrypted}")
print(f"Decrypted: {decrypted}")