A Python implementation of the Vigenère cipher — a polyalphabetic substitution cipher that uses dynamic keyword-based encryption/decryption.
The Vigenère cipher is a classic cryptographic method that enhances security compared to simple substitution ciphers. It encrypts text by shifting letters according to a repeating keyword, making frequency analysis attacks harder.
- Encrypt/decrypt text with a custom keyword
- Preserves spaces and punctuation
- Case-insensitive input handling
- Simple command-line execution
Clone the repository:
git clone https://github.com/fahadelahikhan/Vigenere-Cipher.git
cd Vigenere-Cipher
# Import functions
from vigenere import encrypt, decrypt
message = "Hello World!"
key = "SECRET"
# Encrypt
encrypted = encrypt(message, key) # Output: "dlwor aeptl!"
# Decrypt
decrypted = decrypt(encrypted, key) # Output: "hello world!"
encrypted_text = "mrttaqrhknsw ih puggrur"
custom_key = "happycoding"
decrypted_text = decrypt(encrypted_text, custom_key)
print(decrypted_text) # Output: "freecodecamp is awesome"
- Encryption:
(plaintext_char + key_char) mod 26
- Decryption:
(ciphertext_char - key_char) mod 26
Non-alphabetic characters (spaces, punctuation) remain unchanged during processing.
Distributed under the MIT License. See LICENSE for details.
Note: While historically significant, the Vigenère cipher is not secure for modern cryptographic needs. Use for educational purposes only.