Vigenère Cipher Explorer
Interactive Vigenère Cipher
Enter your text and key to see the Vigenère cipher in action.
Vigen\u00e8re Cipher
About Vigenère Cipher
Description
The Vigenère cipher is a polyalphabetic substitution cipher that uses a keyword to shift each letter of the plaintext. It was considered unbreakable for centuries and is an improvement over simpler ciphers like the Caesar cipher.
How it Works
- Choose a keyword and repeat it to match the length of the plaintext.
- For each letter in the plaintext:
- Find the corresponding letter in the keyword.
- Use the keyword letter to determine the shift (A=0, B=1, C=2, etc.).
- Shift the plaintext letter by this amount (wrapping around the alphabet if necessary).
- The result is the ciphertext.
Strengths
- Resistant to simple frequency analysis
- Multiple cipher alphabets make it more secure than monoalphabetic ciphers
- Relatively easy to implement and use manually
Weaknesses
- Vulnerable to Kasiski examination for key length determination
- Once key length is known, it can be treated as multiple Caesar ciphers
- Repetition in the key can lead to patterns in the ciphertext
Historical Context
The Vigenère cipher was invented by Giovan Battista Bellaso in 1553 but misattributed to Blaise de Vigenère in the 19th century. It gained the nickname "le chiffre indéchiffrable" (the indecipherable cipher) and remained unbroken until Friedrich Kasiski published a general method of deciphering in 1863.
Modern Applications
While the Vigenère cipher is not secure for modern cryptographic purposes, it serves as an excellent educational tool. It introduces important concepts like polyalphabetic substitution and the use of keys in encryption. Understanding the Vigenère cipher and its vulnerabilities provides valuable insights into the development of more advanced encryption methods.
Caesar Cipher Implementations
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}")