Keyword Cipher: Encoder, Decoder, and Alphabet Mapping
Use a keyword-based substitution alphabet to encrypt and decrypt text, inspect letter mappings, and compare frequency patterns for manual analysis.
Alphabet Mapping
Standard Alphabet
Cipher Alphabet
On This Page
Article sections
Frequently Asked Questions About Keyword Cipher
What is a keyword cipher?
A keyword cipher is a monoalphabetic substitution cipher that builds a custom alphabet from a keyword. Unique keyword letters come first, then the remaining unused letters are appended in normal order.
How do you create a keyword cipher alphabet?
Write the keyword, remove duplicate letters, and then append the rest of the alphabet while skipping letters already used. The resulting alphabet becomes the substitution mapping.
How do you decrypt a keyword cipher?
If you know the keyword, regenerate the cipher alphabet and reverse the substitution. If you do not know the keyword, frequency analysis and pattern matching can help recover likely mappings.
What makes a good keyword?
Longer keywords with many unique letters scramble more of the alphabet and are harder to guess. Avoid short or alphabetically ordered words.
Related Ciphers
Swaps every letter for another using one scrambled alphabet as the key
Shifts each letter by a fixed number of positions in the alphabet
Reverses the alphabet so A becomes Z, B becomes Y, and so on
Applies a linear function to each letter position modulo 26
You May Also Like
Keyword Cipher: Classical Substitution Encryption - Free Online Tool
The Keyword cipher is one kind of substitution cipher: instead of an arbitrary scrambled alphabet, it builds the cipher alphabet from a keyword, so the whole key can be remembered as one word. Unlike simple shift ciphers, keyword ciphers provide variable substitution patterns that make them more resistant to basic cryptanalysis while remaining accessible for educational purposes.
How the Keyword Cipher Works
The keyword cipher creates a substitution alphabet by placing a chosen keyword at the beginning of the cipher alphabet, followed by the remaining letters in standard alphabetical order.
Algorithm Process
-
Keyword Preparation: Remove duplicate letters and convert to uppercase
- Example: "grandmother" → "GRANDMOTHE"
-
Remaining Letters: Identify letters not in the keyword
- Remaining: BCFIJKLPQSUVWXYZ
-
Cipher Alphabet: Combine keyword + remaining letters
- Final: GRANDMOTHEBCFIJKLPQSUVWXYZ
-
Letter Mapping: Create substitution table
- A→G, B→R, C→A, D→N, E→D...
Keyword Cipher Examples
The examples below were all produced with the encoder on this page. To encrypt, find each plaintext letter in the top row and write down the letter beneath it; to decrypt, do the reverse.
Example 1: Keyword ZEBRAS
Keyword: ZEBRAS
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: ZEBRASCDFGHIJKLMNOPQTUVWXY
Message: MEET AT DAWN
Encrypted: JAAQ ZQ RZVK
M sits above J, E above A, T above Q, and so on. The doubled E in MEET becomes a doubled A, so word patterns survive encryption.
Example 2: A Keyword with Repeated Letters
Only the first occurrence of each letter is kept, so SECRET shrinks to SECRT before the rest of the alphabet is appended:
Keyword: SECRET → SECRT
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: SECRTABDFGHIJKLMNOPQUVWXYZ
Message: ATTACK AT MIDNIGHT
Encrypted: SQQSCH SQ JFRKFBDQ
Notice that U through Z map to themselves. A keyword that uses only letters from the first part of the alphabet leaves the tail of the alphabet unchanged, which is one reason longer, more varied keywords are preferred.
Example 3: Mixed-Case Text
With case preservation on (the default), uppercase letters stay uppercase and lowercase stay lowercase:
Keyword: CIPHER
Cipher: CIPHERABDFGJKLMNOQSTUVWXYZ
Message: The Quick Brown Fox
Encrypted: Tbe Oudpg Iqmwl Rmx
Example 4: Decrypting with a Known Keyword
You receive "Tcr hrttrq ds hktr" and know the keyword is KANGAROO. Build the cipher alphabet (KANGRO followed by the unused letters), then look up each ciphertext letter in the bottom row and read the letter above it:
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: KANGROBCDEFHIJLMPQSTUVWXYZ
Ciphertext: Tcr hrttrq ds hktr
Plaintext: The letter is late
Python Implementation
import string
def cipher_alphabet(keyword):
seen = []
for ch in keyword.upper() + string.ascii_uppercase:
if ch in string.ascii_uppercase and ch not in seen:
seen.append(ch)
return ''.join(seen)
def keyword_cipher(text, keyword, decrypt=False):
plain, cipher = string.ascii_uppercase, cipher_alphabet(keyword)
src, dst = (cipher, plain) if decrypt else (plain, cipher)
table = str.maketrans(src + src.lower(), dst + dst.lower())
return text.translate(table)
print(keyword_cipher("MEET AT DAWN", "ZEBRAS")) # JAAQ ZQ RZVK
print(keyword_cipher("JAAQ ZQ RZVK", "ZEBRAS", decrypt=True)) # MEET AT DAWN
Free Online Keyword Cipher Tool Features
Our comprehensive keyword cipher tool includes:
- Bidirectional Processing: Both encryption and decryption modes
- Custom Keywords: Use any keyword to generate unique cipher alphabets
- Case Preservation: Options to maintain original text formatting
- Character Set Support: Handle spaces and punctuation appropriately
- Alphabet Mapping Visualization: See how letters transform
- Frequency Analysis: Built-in statistical analysis tools
- Random Keyword Generator: Generate secure keywords automatically
Security Analysis and Cryptanalysis
Despite their historical importance, keyword ciphers are fundamentally vulnerable to modern cryptanalytic techniques:
Frequency Analysis Vulnerability
- Method: Statistical analysis of letter frequencies
- Requirement: Approximately 27.6 letters of ciphertext
- Process: Compare cipher frequencies to expected English frequencies (E=12.02%, T=9.06%, A=8.12%)
- Success Rate: Very high with sufficient text
Pattern Recognition Attacks
- Method: Identify common words and patterns
- Targets: Articles ("THE", "AND"), repeated words
- Indicators: Word lengths, punctuation patterns
- Automation: Modern algorithms process thousands of possibilities
Related Cipher Methods
Explore these related classical encryption techniques:
- Caesar Cipher: Simple shift-based substitution cipher
- Caesar Cipher Decoder: Automatically decode encrypted messages
- Atbash Cipher: Ancient Hebrew mirror encryption
- Polybius Cipher: Grid-based coordinate encryption
- Pigpen Cipher: Symbol-based visual encryption
Further Reading
Explore keyword cipher history, advanced cryptanalysis, and code implementations:
- Keyword Cipher: History, Cryptanalysis & Implementation Guide — From ancient diplomatic encryption to modern MCMC solving techniques, with Python and JavaScript code