Vigenère Cipher

Nerd Cafe

The Vigenère Cipher is a polyalphabetic substitution cipher that uses a keyword to encrypt and decrypt text. It shifts each letter in the plaintext by a number of positions determined by the corresponding letter in the keyword.

Step 1: Understand the Cipher

The alphabet is indexed from 0 to 25:

A = 0, B = 1, C = 2, ..., Z = 25

Each letter in the plaintext is shifted by the numeric value of the corresponding letter in the keyword.

Step 2: Encryption Steps

  • Choose the plaintext: The message to be encrypted.

  • Choose a keyword: A word or phrase that determines the shifts.

  • Repeat the keyword: Extend the keyword to match the length of the plaintext.

  • Shift the letters:

    • For each letter in the plaintext, determine its shift using the corresponding letter in the keyword.

  • The formula for encryption is:

Ci=(Pi+Ki)    mod    26C_{i}=(P_{i}+K_{i})\;\;mod\;\;26

Where:

  • 𝐶𝑖 is the cipher letter.

  • 𝑃𝑖 is the plaintext letter index.

  • 𝐾𝑖 is the keyword letter index.

Step 3: Decryption Steps

To decrypt, reverse the process:

Pi=(CiKi+26)    mod    26P_{i}=(C_{i}-K_{i}+26)\;\;mod\;\;26

Practical Example

Encryption

  • Plaintext: HELLO

  • Keyword: KEY

Extend the keyword: Repeat KEY to match the plaintext length:

Alphabet indexes:

Apply the formula 𝐶𝑖=(𝑃𝑖+𝐾𝑖) mod 26:

Ciphertext: RIJVS

Decryption

  • Ciphertext: RIJVS

  • Keyword: KEY

  • Extended keyword: K E Y K E

  • Alphabet indexes:

Apply the formula 𝑃𝑖=(𝐶𝑖−𝐾𝑖+26) mod 26:

Decrypted plaintext: HELLO

Key Points

  • The keyword determines the shifts. Longer and complex keywords make the cipher stronger.

  • The Vigenère cipher is not secure against modern cryptanalysis methods like frequency analysis.

Step 4: Python Code

I've implemented the Vigenère Cipher in Python. The code includes both encryption and decryption functions, along with an example usage section.

Output:

Last updated