Gronsfeld Cipher
Nerd Cafe
The Gronsfeld Cipher is a variant of the Vigenère cipher but uses only numeric keys, making it simpler. Each digit in the key determines how many positions to shift the corresponding letter in the plaintext.
Steps to Encrypt and Decrypt Using the Gronsfeld Cipher
Choose a numeric key: The key is a sequence of digits (e.g., 31415).
Prepare the plaintext: Write down the message you want to encrypt, e.g., "
HELLO
".Repeat the key: If the key is shorter than the plaintext, repeat it to match the length of the plaintext.
Encrypt the plaintext: For each letter in the plaintext:
Convert the letter to its position in the alphabet (A=0, B=1, ..., Z=25).
Add the corresponding digit from the key.
Wrap around using modulo 26 if the result exceeds 25.
Convert the result back to a letter.
Decrypt the ciphertext: Reverse the process by subtracting the key digits instead of adding.
Practical Example: Encryption
Inputs:
Plaintext: HELLO
Key: 31415
Encryption Process:
Convert the letters of the plaintext to their numeric positions:
Repeat the key to match the length of the plaintext:
Add each key digit to the corresponding plaintext letter (modulo 26):
Resulting ciphertext:
Practical Example: Decryption
Inputs:
Ciphertext: KFPMT
Key: 31415
Decryption Process:
Convert the letters of the ciphertext to their numeric positions:
Subtract each key digit from the corresponding ciphertext letter (modulo 26):
Resulting plaintext:
Python Code
The Python code for the Gronsfeld Cipher has been implemented. It includes both encryption and decryption functions, along with an example usage.
Output
Last updated