ArticleslgStudy

computer science

Substitution cipher

Substitution cipher is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Substitution cipher rather than just read about it. In short: In cryptography, a substitution cipher is a method of encrypting that creates the ciphertext (its output) by replacing units of the plaintext (its input) in a defined manner, with the help of a key; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing the inverse substitution process to extract t…

Substitution cipher — main illustration
Substitution cipher — illustration

Key takeaways

  • Substitution cipher belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Substitution cipher to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Substitution cipher from memory before moving on to harder problems.

Reference excerpt

In cryptography, a substitution cipher is a method of encrypting that creates the ciphertext (its output) by replacing units of the plaintext (its input) in a defined manner, with the help of a key; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing the inverse substitution process to extract the original message. Substitution ciphers can be compared with transposition ciphers. In a transposition cipher, the units of the plaintext are rearranged in a different and usually quite complex order, but the units themselves are left unchanged. By contrast, in a substitution cipher, the units of the plaintext are retained in the same sequence in the ciphertext, but the units themselves are altered. There are a number of different types of substitution cipher. If the cipher operates on single letters, it is termed a simple substitution cipher; a cipher that operates on larger groups of letters is termed polygraphic. A monoalphabetic cipher uses fixed substitution over the entire message, whereas a polyalphabetic cipher uses a number of substitutions at different positions in the message, where a unit from the plaintext is mapped to one of several possibilities in the ciphertext and vice versa. The first ever published description of how to crack simple substitution ciphers was given by Al-Kindi in A Manuscript on Deciphering Cryptographic Messages written around 850 AD. The method he described is now known as frequency analysis.

Types

Simple

The simplest substitution ciphers are the Caesar cipher and Atbash cipher. Here single letters are substituted (referred to as simple substitution). It can be demonstrated by writing out the alphabet twice, once in regular order and again with the letters shifted by some number of steps or reversed to represent the ciphertext alphabet (or substitution alphabet). The substitution alphabet could also be scrambled in a more complex fashion, in which case it is called a mixed alphabet or deranged alphabet. Traditionally, mixed alphabets may be created by first writing out a keyword, removing repeated letters in it, then writing all the remaining letters in the alphabet in the usual order. Using this system, the keyword "zebras" gives us the following alphabets:

A message

flee at once. we are discovered!

enciphers to

SIAA ZQ LKBA. VA ZOA RFPBLUAOAR!

And the keyword "grandmother" gives us the following alphabets:

The same message

flee at once. we are discovered!

enciphers to

MCDD GS JIAD. WD GPD NHQAJVDPDN!

Usually the ciphertext is written out in blocks of fixed length, omitting punctuation and spaces; this is done to disguise word boundaries from the plaintext and to help avoid transmission errors. These blocks are called "groups", and sometimes a "group count" (i.e. the number of groups) is given as an additional check. Five-letter groups are often used, dating from when messages used to be transmitted by telegraph:

SIAAZ QLKBA VAZOA RFPBL UAOAR

If the length of the message happens not to be divisible by five, it may be padded at the end with "nulls". These can be any characters that decrypt to obvious nonsense, so that the receiver can easily spot them and discard them. The ciphertext alphabet is sometimes different from the plaintext alphabet; for example, in the pigpen cipher, the ciphertext consists of a set of symbols derived from a grid. For example:

Such features make little difference to the security of a scheme, however; at the very least, any set of strange symbols can be transcribed back into an A-Z alphabet and dealt with as normal. In lists and catalogues for salespeople, a very simple encryption is sometimes used to replace numeric digits by letters.

Examples: MAT would be used to represent 120, PAPR would be used for 5256, and OFTK would be used for 7803.

Security Although the traditional keyword method for creating a mixed substitution alphabet is simple, a serious disadvantage is that the last letters of the alphabet (which are mostly low frequency) tend to stay at the end. A stronger way of constructing a mixed alphabet is to generate the substitution alphabet completely randomly. Although the number of possible substitution alphabets is very large (26! ≈ 288.4, or about 88 bits), this cipher is not very strong, and is easily broken. Provided the message is of reasonable length (see below), the cryptanalyst can deduce the probable meaning of the most common symbols by analyzing the frequency distribution of the ciphertext. This allows formation of partial words, which can be tentatively filled in, progressively expanding the (partial) solution (see frequency analysis for a demonstration of this). In some cases, underlying words can also be determined from the pattern of their letters; for example, the English words tater, ninth, and paper all have the pattern ABACD. Many people solve such ciphers for recreation, as with cryptogram puzzles in the newspaper. According to the unicity distance of English, 27.6 letters of ciphertext are required to crack a mixed alphabet simple substitution. In practice, typically about 50 letters are needed, although some messages can be broken with fewer if unusual patterns are found. In other cases, the plaintext can be contrived to have a nearly flat frequency distribution, and much longer plaintexts will then be required by the cryptanalyst.

Nomenclator

… excerpt ends here. Continue reading the full article.

Illustrations

Substitution cipher: The forged nomenclator message used in the Babington Plot in 1586
The forged nomenclator message used in the Babington Plot in 1586
Substitution cipher: A French nomenclator code table
A French nomenclator code table
Substitution cipher: Enigma cipher machine as used by the German military in World War II
Enigma cipher machine as used by the German military in World War II

Worked examples

Example 1 — a first encounter with Substitution cipher

Start with the simplest possible case. Write down what Substitution cipher claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Substitution cipher before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Substitution cipher ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Substitution cipher

In research
Substitution cipher appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Substitution cipher in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Substitution cipher is common in secondary-school and first-year university syllabi. It links to neighbouring topics Classical ciphers, Fictional languages, History of cryptography, so understanding it makes those chapters shorter.
In everyday life
Look for Substitution cipher outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Substitution cipher in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Substitution cipher means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Substitution cipher out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Substitution cipher in simple terms?

In cryptography, a substitution cipher is a method of encrypting that creates the ciphertext (its output) by replacing units of the plaintext (its input) in a defined manner, with the help of a key; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures…

Why does Substitution cipher matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Substitution cipher?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Substitution cipher.

Tags

  • Classical ciphers
  • Fictional languages
  • History of cryptography

Keep exploring