The Vigenère Cipher is a method of encrypting alphabetic text through a form of polyalphabetic substitution. Unlike the Caesar cipher, which shifts each letter by the same amount, the Vigenère cipher shifts letters based on a keyword. Each letter of the plaintext is shifted by a number corresponding to the letter in the keyword.
Here’s how it works:
- Choose a keyword: This keyword will repeat across the plaintext to determine how much each letter is shifted.
- Encryption: For each letter in the plaintext:
- Find the corresponding letter in the keyword.
- Convert both the plaintext letter and the keyword letter into a number (A=0, B=1, C=2, …, Z=25).
- Add the numbers together.
- If the sum is greater than 25, subtract 26 (to keep it within the 0-25 range).
- Convert the resulting number back to a letter.
- Decryption: To decrypt, reverse the process:
- For each letter in the ciphertext, subtract the number corresponding to the keyword letter (instead of adding).
- If the result is negative, add 26 to bring it back within the valid range (0-25).
Example:
Let’s say your plaintext is “HELLO” and your keyword is “KEY“.
- Repeat the keyword so that it matches the length of the plaintext: “KEYKE“.
- Convert each letter to a number (A=0, B=1, …, Z=25):
- Plaintext: H=7, E=4, L=11, L=11, O=14
- Keyword: K=10, E=4, Y=24, K=10, E=4
- Encrypt by adding the plaintext number to the keyword number:
- (7 + 10) % 26 = 17 → R
- (4 + 4) % 26 = 8 → I
- (11 + 24) % 26 = 9 → J
- (11 + 10) % 26 = 21 → V
- (14 + 4) % 26 = 18 → S
- The ciphertext is: RIJVS.