Lesson 2 of 15
Vigenère Cipher
Vigenère Cipher
The Vigenère cipher (1553) extends the Caesar cipher by using a keyword instead of a single shift. Each letter of the plaintext is shifted by the corresponding letter of the key (cycling through the key).
Encryption
Given plaintext and key (both uppercase letters), the -th ciphertext letter is:
where letter values are A=0, B=1, …, Z=25.
Decryption
Example
| Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| Plaintext | H | E | L | L | O |
| Key | K | E | Y | K | E |
| Shift | 10 | 4 | 24 | 10 | 4 |
| Cipher | R | I | J | V | S |
HELLOwith keyKEY→RIJVS
Security
The Vigenère cipher defeated frequency analysis for centuries — it was called the "le chiffre indéchiffrable" (the indecipherable cipher). Charles Babbage and Friedrich Kasiski independently broke it in the 19th century using the Kasiski test, which exploits repeated key cycles.
Your Task
Implement (uppercase alphabetic characters only; non-alpha characters are skipped):
vigenere_encrypt(text, key)— encrypt using the Vigenère ciphervigenere_decrypt(text, key)— decrypt
Python runtime loading...
Loading...
Click "Run" to execute your code.