Enter your text and key to see the Vigenère cipher in action.
Examples of Caesar Cipher implementation in various programming languages.
def vigenere_encrypt(text, key):
key = key.upper()
text = text.upper()
encrypted = ""
key_index = 0
for char in text:
if char.isalpha():
shift = ord(key[key_index]) - ord('A')
encrypted += chr(((ord(char) - ord('A') + shift) % 26) + ord('A'))
key_index = (key_index + 1) % len(key)
else:
encrypted += char
return encrypted
def vigenere_decrypt(text, key):
key = key.upper()
text = text.upper()
decrypted = ""
key_index = 0
for char in text:
if char.isalpha():
shift = ord(key[key_index]) - ord('A')
decrypted += chr(((ord(char) - ord('A') - shift) % 26) + ord('A'))
key_index = (key_index + 1) % len(key)
else:
decrypted += char
return decrypted
# Example usage
key = "KEYWORD"
plaintext = "HELLO WORLD"
encrypted = vigenere_encrypt(plaintext, key)
decrypted = vigenere_decrypt(encrypted, key)
print(f"Encrypted: {encrypted}")
print(f"Decrypted: {decrypted}")