substitution cipher with different alphabet length
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
A substitution cipher is one of the simplest and most fundamental encryption methods. In this cipher, each element in the plaintext is mapped to another element using a predetermined system. Despite its simplicity, understanding the nuances of substitution ciphers can provide insight into more complex cryptographic systems. This article explores substitution ciphers with various alphabet lengths, providing technical examples and deeper understanding.
Basic Concepts
What is a Substitution Cipher?
A substitution cipher involves substituting each letter or symbol in the plaintext with a corresponding letter or symbol in the ciphertext. The mapping from plaintext to ciphertext is defined by a cipher alphabet.
Mathematical Representation
If we denote the plaintext alphabet by , the ciphertext alphabet by , and the substitution cipher by a function , then for any letter , we have:
History and Usage
Substitution ciphers have a rich history, from the ancient Caesar cipher to complex polyalphabetic ciphers used throughout the ages. They lay the groundwork for understanding more sophisticated cryptographic systems.
Different Alphabet Lengths
Standard 26-Letter Alphabet
The traditional substitution cipher uses the standard 26-letter English alphabet. In this system, each letter in the alphabet is replaced with another:
| Plaintext | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| Ciphertext | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C |
This illustration demonstrates a simple Caesar cipher with a shift of 3.
Beyond 26: Extended Alphabets
Substitution ciphers can also operate on extended alphabets, such as:
- Alphanumeric (36 characters): Includes numbers (0-9) alongside the 26 English letters.
- ASCII (128 characters): Comprising printable characters and control characters.
Let's consider an example using an alphanumeric alphabet:
| Plaintext | 0 | 1 | 2 | ... | A | B | ... | Z |
| Ciphertext | 5 | 9 | 7 | ... | Y | L | ... | Q |
Symbols and Multilingual Alphabets
Incorporating symbols and letters from other languages can increase complexity and security. For instance, a substitution cipher can include accented characters (e.g., in a French or Spanish alphabet).
Types of Substitution Ciphers
Monoalphabetic Cipher
A monoalphabetic substitution uses a fixed alphabet for substitution throughout the message. However, this predictability makes it vulnerable to frequency analysis attacks.
Example:
Using the cipher key below for a monoalphabetic substitution:
- Plaintext Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
- Ciphertext Alphabet: QWERTYUIOPLKJHGFDSAZXCVBNM
Encrypt HELLO
to ITSSG
.
Polyalphabetic Cipher
This cipher uses multiple alphabets to encode the text, making frequency analysis more challenging. The most famous polyalphabetic cipher is the Vigenère cipher.
Vigenère Cipher Example:
With the keyword KEY
, encrypt the plaintext HELLO
:
- Align keyword:
KEYKE - Convert to numbers: H=7, E=4, L=11, L=11, O=14; K=10, E=4, Y=24
- Add numbers: (7+10)=17, (4+4)=8, etc... (mod 26)
- Result: RILAO
Benefits and Limitations
Benefits
- Simplicity: Easy to implement and understand.
- Foundation: Forms the basis for more sophisticated ciphers.
Limitations
- Security: Prone to frequency analysis, especially with monoalphabetic ciphers.
- Scalability: As message length grows, complexity increases, especially for extended alphabets.
Summarization with a Table
| Characteristic | Monoalphabetic Substitution | Polyalphabetic Substitution | Considerations |
| Uses | Single alphabet | Multiple alphabets | Increased complexity in polyalphabetic versions |
| Resistance | Weak to frequency analysis | Stronger against analysis | Frequency attacks are less effective |
| Encryption | One-to-one mapping | One-to-many mapping | Varies depending on the system used |
| Example Cipher | Caesar Cipher | Vigenère Cipher | Demonstrates basic vs. complex applications |
Conclusion
Substitution ciphers, though simple in design, provide a foundation for understanding cryptography. By exploring different alphabet lengths and types, we can appreciate both the strengths and vulnerabilities inherent in these systems. As technology and needs evolved, so did cryptographic methods, leading to more secure and complex systems beyond basic substitution ciphers.
Related reading
- Suddenly getting Unable to connect to the server net/http TLS handshake timeout from kubectl
- System design Preventing/detecting vote fraud
- System.Security.SecurityException The source was not found, but some or all event logs could not be searched. Inaccessible logs Security
- terraform kubernetes provider - tls secret not created properly
- The apk must be signed with the same certificates as the previous version
- The author primary signature's timestamp found a chain building issue UntrustedRoot self signed certificate in certificate chain
- The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256
- The AWS Access Key Id does not exist in our records

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.