cryptography
substitution cipher
encryption
alphabet variation
code breaking

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.

Practice system design

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 PP, the ciphertext alphabet by CC, and the substitution cipher by a function ff, then for any letter pPp \in P, we have:

c=f(p)wherecCc = f(p) \quad \text{where} \quad c \in C

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:

PlaintextABCDEFGHIJKLMNOPQRSTUVWXYZ
CiphertextDEFGHIJKLMNOPQRSTUVWXYZABC

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:

Plaintext012...AB...Z
Ciphertext597...YL...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 :

  1. Align keyword: KEYKE
  2. Convert to numbers: H=7, E=4, L=11, L=11, O=14; K=10, E=4, Y=24
  3. Add numbers: (7+10)=17, (4+4)=8, etc... (mod 26)
  4. 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

CharacteristicMonoalphabetic SubstitutionPolyalphabetic SubstitutionConsiderations
UsesSingle alphabetMultiple alphabetsIncreased complexity in polyalphabetic versions
ResistanceWeak to frequency analysisStronger against analysisFrequency attacks are less effective
EncryptionOne-to-one mappingOne-to-many mappingVaries depending on the system used
Example CipherCaesar CipherVigenère CipherDemonstrates 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.