# Guide to Codes and Ciphers

Note: This is a Guide not a Puzzle

s are quite common now on puzzling, and at first can seem quite confusing. But ciphers are bigger than this site, used worldwide by companies and secret services to encrypt data.

But what is a cipher, and what's the difference between a code and a cipher? What types of codes and ciphers are there and how can I make or solve them?

(The main purpose of this post is to help out newcomers to the site who may be a bit daunted or confused at the sight of ciphers, but who knows? An experienced user could learn something here too, I certainly did in my research :) )

• Posted this after a suggestion from n_palum and deusovi. If you want to add your own answer, feel free! Also if you want clarification on any of the ciphers just ask. – Beastly Gerbil May 25 '17 at 6:23
• @Matsmath I've edited a link into the cipher tag info (edit pending) and users can redirect. – Beastly Gerbil May 25 '17 at 16:46
• You should also mention the difference between a code and a cipher/encryption, since these words are used a bit interchangingly in daily conversations. As well as mention that you can put code in a cipher... and send a cipher by code (eg. morse or ASCII). And that there are some overlap - eg. Caesar is a cipher, but could also be thought of as a code (and it does sort of have a code-table). Or the simple A=1, B=2, C=3... is it a code or a cipher? Remember A=65 (ASCII) certainly are just code... – Baard Kopperud May 26 '17 at 23:45
• @BaardKopperud great idea. And will do :) – Beastly Gerbil May 27 '17 at 9:57

This guide aims to explain various ciphers, help you understand how they work, and how to decode them with or without a key.

This answer is currently being split into multiple posts to improve scrollability and readability after some advice from other users. This may take a while, and apologies for the stop-start fashion of it.

Mission accomplished! This answer now contains links to separate posts of different types of ciphers, so there is no character limit allowing me to elaborate in more detail and to stop you having to scroll. Thanks a lot to @n_palum for helping!

Index:

• What is a cipher?
• Brief History
• Definition
• How to make a good one
• Difference between Codes and Ciphers
• Types of cipher
• Classes and definitions
• Transposition ciphers
• Monoalphabetic Substitution ciphers
• Polygraphic Substitution ciphers
• Polyalphabetic ciphers
• Other ciphers
• Mechanical Ciphers
• Cryptanalysis
• Frequency Analysis
• Index of Coincidence
• Kasiski Examination
• Resources

# What is a cipher?

### Brief History

Ciphers have played major parts in historical events dating back to around 1900 BCE where apparent nonsense hieroglyphics can be found. From there, ciphers have developed, a recipe found encrypted on a tablet from 1500 BCE, and Hebrew scholars using monoalphabetic ciphers in 600 BCE. Nowadays, ciphers are common, encryption used by companies, secret services and even everyday applications such as Whatsapp. They make the world a lot more secure, but what actually are these ciphers?

### Definition

A cipher is, simply put, a way of hiding data using a disguised way of writing. It is usually an algorithm with the purpose of converting data to a code to stop outside parties from obtaining the data and allowing only the intended recipient access.

A cipher consists of at least two, often 3 pieces of data:

• The plaintext - the message or data which shall be encoded
• The key (Not used for all ciphers) - A piece of data which is required to decode the ciphertext to the plaintext
• The ciphertext - the encoded plaintext which is usually illegible

The process of encryption is

Plaintext -> Method of encryption (type of cipher) + Key (if required) -> Ciphertext

Decryption is the reverse.

### How to make a good one

On puzzling, we don't want to just see a short string and be expected to solve it. For what to do and what not to do see this meta post

### Difference between a Code and a Cipher

For everyone but cryptographers, the words code and cipher are synonymous. If you were to talk about codes and ciphers to someone you'd probably find they used the words interchangeably. But there is a difference.

Codes are everywhere, and you won't even notice the most of the time. A code replaces words or entire sentences or phrases with symbols or characters. The important thing here is that each set of symbols or characters have a meaning. These meanings are usually stored in a code book. For instance, telegraph communicators used code to convey messages quicker, here is an extract of one of their codebooks: You can see different words on their own can mean whole sentences.

Codes are very common, and you use them without even thinking. A traffic light uses a colour code for the words 'stop', 'wait' and 'go'. Most people use code every day, probably including you, whilst talking in chat or texting things like 'brb', 'afaik' and 'idk'. The most common code, used for information interchange, is ASCII.

The point of codes isn't really to hide data, just converting it to an easier way to transmit.

A cipher, on the other hand, the ciphertext has no meaning whatsoever. Each character is replaced according to an algorithm. For instance, Morse code isn't a code, it's actually a cipher.

Most ciphers were invented to hide data.

The difference broken down:

Codes generally operate on semantics, meaning, while ciphers operate on syntax, symbols. A code is stored as a mapping in a codebook, while ciphers transform individual symbols according to an algorithm.

# Types of cipher

### Classes and definitions

There are two different categories of ciphers: Classical (pen and paper) and the more modern Mechanical (requires a machine).

There are several different classes of classical ciphers, as listed below:

• Transposition ciphers - Positions of the characters in the plaintext change, but the characters themselves remain the same
• Monoalphabetic substitution ciphers - Each character (not always true, but most) is replaced with a different character(s)
• Polygraphic substitution ciphers - Groups of characters are replaced
• Polyalphabetic ciphers - Characters are encoded using a different alphabet. Usually position dependent.
• Others - Completely different, or above classes are combined

There are a few mechanical ciphers, which I will write a brief note on after the classical ciphers below.

### Transposition ciphers

Transposition ciphers involve moving the characters in the plaintext to different positions using an algorithm. The characters themselves remain unchanged, making this type of cipher insecure for short plaintexts.

See this separate answer for more details on different types of transposition ciphers.

### Monoalphabetic substitution ciphers

Monoalphabetic substitution ciphers replace each letter in the plaintext with a different character/group of characters. If the plaintext is lengthy then these can be easily broken by frequency analysis.

See this separate answer for more details on different types of monoalphabetic substitution ciphers.

### Polyalphabetic Substitution Ciphers

Polyalphabetic Substitution ciphers involve replacing characters in the plaintext with characters/groups of characters from an alternate alphabet.

See this separate answer for more details on different types of polyalphabetic substitution ciphers.

### Polygraphic Ciphers

Polygraphic ciphers involve having groups of characters in the plaintext replaced.

See this separate answer for more details on different types of polygraphic ciphers.

### Other ciphers

Other ciphers are out there and many don't fit into any of the above categories. They can be combination ciphers, combining elements above to make them stronger, or just be completely different.

See this separate answer for more details on different types of other ciphers.

Also, see this community wiki of other ciphers that have been missed out, and feel free to add to it!

### Mechanical ciphers

Mechanical ciphers were invented in WWII. They rely on gearing mechanisms to shift letters through an alphabet to get the final message.

Most famous examples are the Enigma machine and the Lorenz machine. I won't be able to explain a machine very well, so I won't bother going into detail. See the links for more, or this list in Wikipedia.

# Cryptanalysis

There are many ways to attempt to break a cipher without a key. Here are the best ways (taken from my answer here):

Cryptanalysis is defined as

'the art or process of deciphering coded messages without being told the key.'

If you have the key and know the encryption method, you can simply reverse the process to get to the plaintext.

If you have the key but not the encryption method, then this question covers how you can identify the cipher

However, if you have neither the key nor the encryption then you can use cryptanalysis.

This can be used to achieve a

• Total break — working out the key and the plaintext.
• Global deduction — discovering the method of encryption and finding the plaintext, but not the key.
• Distinguishing algorithm — identifying the cipher from a random permutation.

There are a couple of different ways to solve ciphers:

### Frequency Analysis

Frequency analysis works best with substitutional or rotational ciphers, though both of those can have keys. Frequency analysis studies the frequency of letters in a ciphertext.

Computers have calculated that in the English language, the order of the most frequent letters from high to low is etaoinshrdlcumwfgypbvkjxqz.

Here is the stats for analysis on the English language, including unigram, bigrams, trigrams etc.

As you can see from this graph, 'e' is by far the most frequent letter. 't' - 'r' is a lot closer.

How to use

If the cipher is a substitution, and the ciphertext is quite large, then you can attempt to break the cipher.

Using an online tool such as this, you can find the most common letters and most frequent substrings.

The most frequent letter in the ciphertext is probably 'e', and so on.

Using this you can break a cipher, or get an almost correct plaintext which you can then deduce the correct plaintext.

### Example

Example found online. This is a known rot cipher, but we don't know what number:

ymnxhtzwxjfnrxytuwtanijdtzbnymijyfnqjipstbqjiljtknrutwyfsyyjhmstqtlnjxfsifuuqnhfyntsymfyfwjzxjinsymjnsyjwsjy

Most common letters:

j = 13, y=13, n=11, t=10.

so we can assume either e = j or y. If e = j, then j is +5 from e so we can assume this is rot 5. Decoding using rot 21 (the reverse) gives:

thiscourseaimstoprovideyouwithdetailedknowledgeofimportanttechnologiesandapplicationthatareusedintheinternet

So we have solved it using just one substitution.

This method really works best with a quite lengthy ciphertext and is almost useless with short ciphertexts.

### Index of coincidence

The index of coincidence provides a measure of how likely it is to draw two matching letters by randomly selecting two letters from a given text, from the formula number of times that letter appears/length of the text

The calculation itself is complex. Here is the calculation, in its most basic form from Wikipedia.

How to use

The basis is that by splitting the ciphertext into groups of x, and stacking them, if the key length = x then the I.C. will be around 1.73 (index coincidence of English language). If it isn't the same as x it will be around 1.

Example

(From Wikipedia)

We have the following ciphertext:

QPWKA LVRXC QZIKG RBPFA EOMFL JMSDZ VDHXC XJYEB IMTRQ WNMEA IZRVK CVKVL XNEIC FZPZC ZZHKM LVZVZ IZRRQ WDKEC HOSNY XXLSP MYKVQ XJTDC IOMEE XDQVS RXLRL KZHOV

We can guess this is vigenere with a short key and its English. We can stack them in, say groups of 3 or any other number:

QPW
KAL
...

So if the key length is x, then the I.C should be around 1.73. Calculating all key lengths of 1-10:

1  1.12
2   1.19
3   1.05
4   1.17
5   1.82
6   0.99
7   1.00
8   1.05
9   1.16
10  2.07

We can see that 5 and 10 are the closest to 1.73, and as 10 is a factor of 5 then the key length will be 5.

Next stack the ciphertext in groups of 5, and using frequency analysis on each column we can find the key. When we try this, the best-fit key letters for each column are "EVERY". A vigenere decoder gives the message:

MUST CHANGE MEETING LOCATION FROM BRIDGE TO UNDERPASS SINCE ENEMY AGENTS ARE BELIEVED TO HAVE BEEN ASSIGNED TO WATCH BRIDGE STOP MEETING TIME UNCHANGED XX

### Kasiski Examination

The Kasiski Examination is another way of deducing the key length. Works best with longer ciphertexts, though a computer is then usually required.

The Kasiski Examination finds the repeated strings in the ciphertext and the distance between them. The distances are likely to be multiples of the keyword length. Finding more repeated strings means it is easier to find the key length, as it is the highest common factor/greatest common divisor of the distances.

### Example

(Courtesy of wikipedia, with some added elaboration.)

Take the plaintext

cryptoisshortforcryptography

'crypto' appears twice in the plaintext, the distance between is 16 characters. (Count from the first c to the r before the second)

If the key is 'abcdef' the length is 6, which doesn't go into 16 we don't get any repeats in the ciphertext:

abcdefabcdefabcdefabcdefabcdefab
cryptoisshortforcryptography
csasxtitukswtgqugwyqvrkwaqjb

'abcdef' matches 'crypto' the first time, but for the second crypto the key is 'efabcd' and as a result, the ciphertext doesn't match.

But if the key is 'abcd', the length is 4 which goes into 16. So the ciphertext repeats:

abcdabcdabcdabcdabcdabcdabcdabcd
cryptoisshortforcryptography
cqwmtngpsgmotemocqwmtneoaofv

You can see that 'abcdab' lines up with 'crypto' both times. And hey presto we get a repeat in the ciphertext: 'cqwmtn'.

### Resources

• The index doesn't link to different parts of the answer? Bah -1000 (But really good job) :) – n_plum May 25 '17 at 12:33
• @n_palum no idea how to link to parts of an answer :P – Beastly Gerbil May 25 '17 at 13:56
• I wonder if you could link it up with html and grabbing the specific div.. sounds like a lot of work :P – n_plum May 25 '17 at 14:06
• @n_palum yeah and I think I'm 2 or 3 characters away from reaching the character limit, sounds like a code golf job :P – Beastly Gerbil May 25 '17 at 14:11
• BTW, a beautiful example of a monoalphabetic substitution is E.A.Poe's "The Gold Bug" - I once spent some boring lesson in the highschool counting letter frequencies and decoding it (the ciphertext was left as-is, while the story was translated to Czech). – Edheldil May 25 '17 at 17:35

Community Wiki of less well-known codes and ciphers not included in Beastly Gerbils answer. Feel free to add to it.

### Tap Code

The tap code is a way of communication using just taps or knocks. It can also be represented by dots in writing.

A 5x5 Polybius square with numbers down the side is used. The person taps the town number, pauses, and then the column number of the letter.

The square:

0  1  2  3    4  5
1  A  B  C/K  D  E
2  F  G  H    I  J
3  L  M  N    O  P
4  Q  R  S    T  U
5  V  W  X    Y  Z

Example:

Encoding the message ESCAPE NOW. For instance 'E' we take the row, 1 and the column, 5 and tap that many times with a gap between: . .....

A double space is used between letters and a / between words

The final ciphertext is

. .....  .... ...  . ...  . .  ... .....  . ..... / ... ...  ... ....  ..... ..

### Pigpen Cipher

The pigpen cipher is a symbolic cipher that uses symbols to replace words. It is also known as the tic-tac-toe cipher.

It uses the following: To encode the plaintext.

Example:

ESCAPE NOW becomes ### Public-key cryptography

This is the 'modern' cipher used commonly.

It has two keys.

The 'public key' is a large number available to anyone (e.g. On a companies website). This number is special because it only has four factors including 1 and itself.

The 'private key' is the two numbers that are the other factors of the public key (Not 1 or itself) When multiplied together they produce the public key.

This is a very secure method because it is very hard to find factors of large numbers.

The diagram below explains: ### End to end encryption (E2EE)

This is an encryption method commonly used by messaging, video messaging and radio services such as WhatsApp and Skype. Your message is sent and is immediately encrypted using a lengthy and unique key. The resulting ciphertext is sent. If intercepted, then the message can not be read. The message is received and decrypted using the same key. The message is then displayed. Only the intended recipient can read the message.

Example:

Gerbil's Note: I have hit the cap on answers so n_palum is kindly answering and allowing me to edit. Please be aware that the text below is written by Beastly Gerbil, so questions should be directed to me if you have any, I don't want n_palum to be hassled :)

# Other ciphers

NOTE: These ciphers often involve aspects from other ciphers, so I advise you read those first.

Both these ciphers were introduced by Germany in WWI, and are named after the possible characters in the ciphertext. The difference between them is that ADFGX uses a 5x5 Polybius square, whereas ADFGVX uses a 6x6 including number 0-9 and i isn't merged with j.

Random key square:

    A D F G X
__________
A | G M K Y O
D | B E N X U
F | S W F D C
G | R T Q L P
X | V Z I H A

Encoding the message COVER TRACKS using the Polybius square method gives

FX AX XA DD GA GD GA XX FX AF FA

Now using the key 'ALERT' with columnar transposition (note I have used the irregular method here):

A L E R T             A E L R T
---------             ---------
F X A X X             F A X X X
A D D G A             A D D G A
G D G A X     -->     G G D A X
X F X A F             X X F A F
F A                   F   A    

Giving the final ciphertext:

Random key square:

    A D F G V X
____________
A | H T A W Z 8
D | 5 6 M 0 L S
F | B D C 3 F V
G | 4 Q P O 2 1
V | R Y 7 9 G E
X | U K J N I X

Encoding COVER TRACKS using this Polybius square:

FF GG FX VX VA AD VA AF FF XD DX

And now using columnar transposition with the key 'HIDE'

H I D E             D E H I
-------             --------
F F G G             G G F F
F X V X             V X F X
V A A D     -->     A D V A
V A A F             A F V A
F F X D             X D F F
D X                     D X

Giving:

GVAAXGXDFDFFVVFDFXAAFX

Affine cipher

The affine cipher is a monoalphabetic substitution variant that uses mathematics.

For english, A=0, B=1, ..., and Z=25. We now need three numbers, $a$, $b$ and $m$.

$m$ = number of letters in the alphabet, 26 for English. $a$ and $b$ can be any numbers between and including 1 and 26.

$a$ can't have any common factors with $b$, it must be relatively prime.

$p$ is the plaintext letter as a number (A0-Z25), and $c$ be the ciphertext letter we are trying to find.

Now we apply the following for every $p$ in the plaintext:

$c = ap+b \ \text{(mod m)}$

To get the ciphertext.

Example:

The message is INFORMATION LEAKED. COVER TRACKS. $a$ = 5, $b$ = 7.

For 'I', $p$ = 8, $m$ = 26. So

$c = 5*8 + 7 \ \text{(mod 26)}$ = $47 \ \text{(mod 26)}$ = $c = 21$

So $c$ = v. Continuing we get the final ciphertext:

vugzophyvzukbhfbwrziboyohrft

Bifid cipher

The bifid cipher uses a 5x5 Polybius square but with numbers. It is unusual as it first enciphers a message, then re-enciphers it by breaking up the result into 'periods' and using the reverse.

Example:

We have the following random square:

    1 2 3 4 5
__________
1 | Y H U Q K
2 | A N M F X
3 | O T R I W
4 | P S Z V G
5 | B E C D L

We replace each letter in the ciphertext with the row-column combination. E.g. 'I' becomes 3-4. Doing this for INFORMATION LEAKED COVER TRACKS, and splitting that into periods of, say 5 gives:

row: 32233 22333 25521 55534 53332 514
col: 42413 31241 25115 24314 13131 352

Appending the column string to the end of the row string in the same block, and splitting into pairs, we then use the square again to get the ciphertext (first two are 32, row 3 column 2 which is 'T'):

3223342413 2233331241 2552125115 5553424314 5333213131 514352
T M I F U  N R R H P  X E H B K  L C S Z Q  C R A O O  B Z E

So the final ciphertext is:

tmifunrrhpxehbklcszqcraoobze

Fractionated Morse Code

Fractionated Morse converts plaintext to Morse, breaks it up and converts it back again using a mixed alphabet key.

Example:

Converting 'COVER TRACKS' to Morse and splitting it into groups of 3 (it must be 3, no other number, x is a space and is added to the end to complete the final trigraph):

-.- .-- -.. .-. .-. x-. -.. --. -.- .-. ..x

Now using the key 'WARNING' to form a mixed alphabet key, we form the following table:

W A R N I G B C D E F H K L M O P Q R S T U V X Y Z
. . . . . . . . . - - - - - - - - - x x x x x x x x
. . . - - - x x x . . . - - - x x x . . . - - - x x
. - x . - x . - x . - x . - x . - x . - x . - x . -

And use it to convert the trigraphs back. The first is '-.-' which is 'F'. We get the final ciphertext:

FIENNUEKFNR

The straddle checkerboard cipher is very strong. The key is a random alphabet permutation and 2 numbers 0-9. A secondary cipher usually comes afterward as well.

Example:

Random key 'kwqynoctaiprhdgevuljmzxfsb' and two random numbers 2 and 9.

    0 1 2 3 4 5 6 7 8 9
____________________
| k w   q y n o c t
2 | a i p r h d g e v u
9 | l j m z x f s b

The alphabet key gets filled, but on the first row, the number columns are left out. They then form rows and the rest is filled in.

We take the row (if there is one) number then column number for each plaintext letter. For COVER TRACKS we get:

C O V  E  R  T R  A  C K S
7 6 28 27 23 8 23 20 7 0 96

76282723823207096

(Secondary example, not necessary but often included): The repeating key of 8412, using non-carrying addition, gives:

 76282723823207096
+84128412841284128
------------------
50300135664481114

Now we re-encode each number. e.g. 5 is 'n':

NKQKKWQNOOYYTWWWY

Trifid Cipher

Trifid is similar to Bifid, but uses 3 3x3 squares formed of all 26 letters + '.' instead.

Each letter gets replaced with square, row, column numbers. The result is split into periods, joined and converted back using the same squares.

Example:

The random key is 'YMJKXNEPSHAQZLDUCVWBTFGO.RI' which forms the three squares:

square 1  square 2  square 3

1 2 3     1 2 3     1 2 3
1 Y M J   1 H A Q   1 W B T
2 K X N   2 Z L D   2 F G O
3 E P S   3 U C V   3 . R I

Encoding INFORMATION LEAKED. COVER TRACKS. we write the numbers vertically and split it into groups of, say 10:

       INFORMATIO NLEAKED.C OVERTRACKS.
square 3133312333 1212112323 2133322113
row    3222311132 2231232332 3331313233
column 3313222333 3212113123 3123222131

Appending each block (the column goes on the end of the row, which goes on the end of the square), we use the 3 squares to re-encode:

313331233332223111323313222333 121211232322312323323212113123 T . V R D Y O T L I K H C G B O O A J N 213332211333313132333123222131 Q R H I T P I N L E

Giving the ciphertext:

T.VRDYOTLIKHCGBOOAJNQRHITPINLE

Gerbil's Note: I have hit the cap on answers so n_palum is kindly answering and allowing me to edit. Please be aware that the text below is written by Beastly Gerbil, so questions should be directed to me if you have any, I don't want n_palum to be hassled :)

# Polygraphic Ciphers

Four Square and Two Square Ciphers

The two and four square ciphers use either two or four 5x5 matrices filled with 25 letters (i is merged with j or q is omitted), often formed using keywords.

Both split the plaintext characters into pairs (digraphs). Each character in a digraph is found in a square, and where they intersect vertically and horizontally is the ciphertext. In two square, if the pair is inline, they stay unchanged. This makes four square more secure.

Two Square Example:

Squares formed with 'WARNING' and 'BEWARE' (squares can be vertical/horizontal. This does affect the final ciphertext):

WARNI     BEWAR
GBCDE     CDFGH
FHKLM     IKLMN
OPQST     OPQST
UVXYZ     UVXYZ

The message in digraphs: 'IN FO RM AT IO NL EA KE DC OV ER TR AC KS'

For the first digraph 'I' is found in the first square, 'N' in the other and where they intersect horizontally and diagonally, we take the letters:

....I     ....r
.....     .....
....m     ....N
.....     .....
.....     .....

The other character in the row replaces the character in the digraph. So 'IN' becomes 'RM'

Final ciphertext:

RMIOAKRPBTW LGIKRC DPUHI TIBBMQ

Four Square Example:

The are two plain alphabet squares in the top left and bottom right (a must), and the two remaining squares formed using keywords. Here they are 'WARNING' and 'BEWARE':

abcde     BEWAR
fghik     CDFGH
lmnop     IKLMN
qrstu     OPQST
vwxyz     UVXYZ

WARNI     abcde
GBCDE     fghik
FHKLM     lmnop
OPQST     qrstu
UVXYZ     vwxyz

The message in digraphs: 'IN FO RM AT IO NL EA KE DC OV ER TR AC KS'

For the first digraph 'I' and 'N' are found in the alphabet squares and the intersection letters in the key squares are the ciphertext letters:

.....     .....
...i.     ..F..
.....     .....
.....     .....
.....     .....

.....     .....
.....     .....
...L.     ..n..
.....     .....
.....     .....

So 'IN' becomes 'FL'. This gives the ciphertext:

FLGFPHAOGLIKBIHIWNIYETPSWWFT

Hill cipher

The hill cipher uses a matrix as a key. It can be any size square, usually a 2x2 or a 3x3.

The plaintext is split into chunks the size of the matrix size (digraphs for a 2x2 matrix, trigraphs for a 3x3 matrix, etc.) The characters are then converted to numbers using A=0, B=1, ..., Z=25 forming a second matrix. The matrices are multiplied, and the result modulo 26 gives the ciphertext.

Example:

Using the following 2x2 matrix as the key:

$\begin{bmatrix} 3 & 1 \\ 5 & 2 \\ \end{bmatrix}$

Splitting INFORMATION LEAKED. COVER TRACKS into pairs gives the first digraph 'IN', which is '8-13' which forms the matrix $\begin{bmatrix}8 \\13 \\\end{bmatrix}$

Now multiplying the matrices together:

$\begin{bmatrix}3 & 1 \\5 & 2 \\\end{bmatrix}$$\begin{bmatrix}8 \\13 \\\end{bmatrix}$ $=$ $\begin{bmatrix}37 \\66 \\\end{bmatrix}$ $\text{(mod 26)}$ $=$ $\begin{bmatrix}11 \\14 \\\end{bmatrix}$ = $\text{'LO'}$

So 'IN' becomes 'LO'.

Continuing gives the final ciphertext:

lodblftmmqyjmuigltlidcwzcewi

Playfair Cipher

The playfair cipher also uses digraphs, and a 5x5 square usually formed with a key (j combined with i).

It works similar to the two or four-square cipher. There are several preparation steps involved for the plaintext:

1. Remove punctuation in plaintext, and convert numbers to words (1 -> 'ONE')
2. If there are consecutive identical letters in a word (e.g 'hello') replace the second occurrence with 'x' ('helxo'). Append an 'x' to the end if the plaintext has an odd amount of characters.
3. Split the plaintext into digraphs
4. Apply rules

Then the rules apply:

1. Pairs of characters in different rows and columns get replaced by the intersection letter in the same row (like 4 square)

2. Pairs on the same row get replaced with the character immediately to the right, wrapping over from the right-hand side to the left-hand side.

3. Pairs in the same column get replaced with the character immediately below, wrapping up from the bottom to the top.

Example:

The key square using keyword 'WARNING':

WARNI
GBCDE
FHKLM
OPQST
UVXYZ

The message after the preparation steps have been applied (only step 3 applies): 'IN FO RM AT IO NL EA KE DC OV ER TR AC KS'

Now examples of rules 1, 2 and 3.

Rule 1 example:

'RM' are in different rows and columns so we take the intersection letters and replace each character by the other in the same row, as we do in 2 or 4 square:

..R.i
.....
..k.M
.....
.....

'RM' becomes 'IK'

Rule 2 example:

'IN' is in the same row. We take the letter on the immediate right and wrap over for 'I' as it is on the far right.

W..NI

'IN' becomes 'WI'

Rule 3 example:

'FO' is in the same column. We take the letter immediately below:

.
.
F
O
U

'FO' becomes 'OU'

Doing this for each digraph gives the final ciphertext:

WIOUIKIPWTDSBIMCEDPUCIQIRBLQ

# Monoalphabetic substitution ciphers

Atbash Cipher

The Atbash cipher is easily broken as it just reverses the alphabet so A=Z, B=Y, ..., Z=A.

ABCDEFGHIJKLMNOPQRSTUVWXYZ
ZYXWVUTSRQPONMLKJIHGFEDCBA

Example:

The message INFORMATION LEAKED. COVER TRACKS becomes

rmulinzgrlm ovzpvw xlevi gizxph

Baconian Cipher

The Baconian cipher gives each letter a string of 5 binary digits (In the original cipher it was 'A' and 'B' but it can be any two characters.)

The following is the alphabet translation table:

A = aaaaa  I/J = abaaa    R = baaaa
B = aaaab    K = abaab    S = baaab
C = aaaba    L = ababa    T = baaba
D = aaabb    M = ababb  U/V = baabb
E = aabaa    N = abbaa    W = babaa
F = aabab    O = abbab    X = babab
G = aabba    P = abbba    Y = babba
H = aabbb    Q = abbbb    Z = babbb

This is then usually followed up with to hide the obviousness of the cipher.

Example:

Encoding the message COVER TRACKS:

C     O     V     E     R     T     R     A     C     K     S
aaaba abbab baabb aabaa baaaa baaba baaaa aaaaa aaaba abaab baaab

Then to hide the cipher using steganography, we can have a=lowercase, b=uppercase and make up a random message

donT trY To ATteMPt a oRgaNised AttAcK on us it will baCkfIre DEeplY

There are a lot of other ways to hide the cipher, such as bold, italic, a certain letter etc.

Caesar Cipher

The Caesar Cipher is the eact same as the ROT cipher. Each letter is 'shifted' x places through the alphabet.

Caesar shift 3 means that each letter is shifted 3 places in the alphabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
XYZABCDEFGHIJKLMNOPQRSTUVW

e.g. A becomes D because A+3 = D.

Example:

The message INFORMATION LEAKED. COVER TRACKS with a Caesar Shift of 3 becomes:

lqirupdwlrq ohdnhg fryhu wudfnv

Substitution Ciphers

A common way of encoding text on puzzling, though less applied in real life nowadays, is to convert the plaintext to a symbolic language such as Braille or Morse.

The Braille alphabet is as follows:

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 ⠵

Numbers are letters a-i with the numerical indicator ⠼ beforehand.

The Morse Alphabet is as follows:

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 --..
0 ----- 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -.... 7 --... 8 ---.. 9 ----.

Some other common ciphers simply convert a message to an alternative language such as ASCII or different bases, such as binary, octal, hexadecimal or base64.

The ASCII alphabet can either be a number or a 7 digit binary code. This table sums it up: Bases:

Bases vary from Base 2 (binary) to Base 64. Here is a conversion table for the most common.

There is also Base64, which is very long and complicated.

Deusovi is thankfully going to post an answer explaining these elements, which I admit I don't have great knowledge on.

Polybius Square

The Polybius Square is a famous cipher and is used in many other combination ciphers.

It uses a 25 letter square with all the letters of the alphabet (i+j merged) to replace each letter with 2 others. The sides of the square are assigned a letter A-E. There will be only 5-6 unique characters in the ciphertext, which makes it easy to identify.

The square can have a key, which starts the alphabet and then the alphabet continues with the remaining letters (e.g. zebracdfghiklmnopqstuvwxy)

Example:

The key is 'cipher' giving 'cipherabdfgklmnoqstuvwxyz'

And the letters round the side are 'ABCDE'

This forms the square:

   A B C D E
__________
A| c i p h e
B| r a b d f
C| g k l m n
D| o q s t u
E| v w x y z

A message is encoded by finding the letter in the square and taking the row then column letter.

Encoding the message COVER TRACKS gives:

C  O  V  E  R   T  R  A  C  K  S
AA DA EA AE BA  DD BA BB AA CB DC

So the ciphertext is

Rot-X cipher

The ROT cipher stands for 'rotational cipher'. The cipher can be ROT1 to ROT25 and letter are rotated the rot number through the alphabet. The most famous rot cipher is ROT13 which can be encoded and decoded the same. The ROT cipher is the same as the Caesar shift cipher.

ROT x can be decoded by ROT (26-x)

The ROT cipher is similar to the Caesar shift cipher, but rotates in the opposite direction.

Example alphabet for rot-13:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
NOPQRSTUVWXYZABCDEFGHIJKLM

Example:

COVER TRACKS in Rot 1, then rot 13, then rot 25:

1:  DPWFS USBDLT
13: PBIRE GENPXF
25: BNUDQ SQZBJR

Simple Substitution Cipher

This uses a jumbled 26 letter key. Like the name suggests it is very simple. If the plaintext is long it is insecure and can be easily broken through frequency analysis.

The plaintext letter is changed to the letter that matches from the key.

Example:

An example 26 letter jumbled key: 'phqgiumeaylnofdxjkrcvstzwb'

Using this key gives the substitution table:

abcdefghijklmnopqrstuvwxyz
phqgiumeaylnofdxjkrcvstzwb

COVER TRACKS becomes

qdsik ckpqlr

Gerbil's Note: I have hit the cap on answers so n_palum is kindly answering and allowing me to edit. Please be aware that the text below is written by Beastly Gerbil, so questions should be directed to me if you have any, I don't want n_palum to be hassled :)

### Polyalphabetic Ciphers

Autokey Cipher

This cipher is similar but more secure than Vigenere. It involves a giant square (26x26) called the tabula recta and a key-word.

The plaintext is written after the key. The whole plaintext is written underneath. For each column, we take the pair as the column and row number.

Here is the tabula recta:

    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
---------------------------------------------------
A   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
B   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 A
C   C 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
D   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
E   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 D
F   F G H I J K L M N O P Q R S T U V W X Y Z A B C D E
G   G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
H   H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
I   I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
J   J K L M N O P Q R S T U V W X Y Z A B C D E F G H I
K   K L M N O P Q R S T U V W X Y Z A B C D E F G H I J
L   L M N O P Q R S T U V W X Y Z A B C D E F G H I J K
M   M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
N   N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
O   O P Q R S T U V W X Y Z A B C D E F G H I J K L M N
P   P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
Q   Q R S T U V W X Y Z A B C D E F G H I J K L M N O P
R   R S T U V W X Y Z A B C D E F G H I J K L M N O P Q
S   S T U V W X Y Z A B C D E F G H I J K L M N O P Q R
T   T U V W X Y Z A B C D E F G H I J K L M N O P Q R S
U   U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
V   V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
W   W X Y Z A B C D E F G H I J K L M N O P Q R S T U V
X   X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
Y   Y Z A B C D E F G H I J K L M N O P Q R S T U V W X
Z   Z 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

Example:

The message INFORMATION LEAKED. COVER TRACKS with the key 'WARNING' gives:

WARNINGINFORMATIONLEAKEDCOVE
INFORMATIONLEAKEDCOVERTRACKS

So we find 'I' on the rows, then the column 'W' (vice versa also works). The intersection is 'E'.

Doing this for all the columns gives the final ciphertext:

Beaufort cipher

This cipher is similar to Autokey but with a repeating key and a different algorithm. Uses the tabula recta too, I won't repeat it see above.

Finding the plaintext letter in the columns, and moving down until the second letter is reached, by moving all the way to the left to the rows the ciphertext letter is found.

Example:

The message INFORMATION LEAKED. COVER TRACKS with the key 'WARNING' gives

WARNINGWARNINGWARNINGWARNING
INFORMATIONLEAKEDCOVERTRACKS

So finding 'I' in the columns and moving down until 'W', it is found it lies in the 'O' row.

The final ciphertext is:

onmzrbgdsdaxjgmwoluscfhangdo

Porta Cipher

The Porta Cipher uses a table with paired letters down one side:

  Keys| 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
---------------------------------------------------------
A,B | n o p q r s t u v w x y z a b c d e f g h i j k l m
C,D | o p q r s t u v w x y z n m a b c d e f g h i j k l
E,F | p q r s t u v w x y z n o l m a b c d e f g h i j k
G,H | q r s t u v w x y z n o p k l m a b c d e f g h i j
I,J | r s t u v w x y z n o p q j k l m a b c d e f g h i
K,L | s t u v w x y z n o p q r i j k l m a b c d e f g h
M,N | t u v w x y z n o p q r s h i j k l m a b c d e f g
O,P | u v w x y z n o p q r s t g h i j k l m a b c d e f
Q,R | v w x y z n o p q r s t u f g h i j k l m a b c d e
S,T | w x y z n o p q r s t u v e f g h i j k l m a b c d
U,V | x y z n o p q r s t u v w d e f g h i j k l m a b c
W,X | y z n o p q r s t u v w x c d e f g h i j k l m a b
Y,Z | z n o p q r s t u v w x y b c d e f g h i j k l m a

(Note: There are different versions of the table, but the result is the same)

The key and plaintext work the same as Beaufort.

Example:

Using the key 'WARNING' on INFORMATION LEAKED. COVER TRACKS forms

WARNINGWARNINGWARNINGWARNING
INFORMATIONLEAKEDCOVERTRACKS

The plaintext letter is found in the pairs and the key letter in the columns. The intersection is the ciphertext letter. This gives:

taniasqivghpxqvryvkcuggjttqc

Running Key

Running Key is the same as Vigenere cipher, but uses a long key not a repeated one such as a book extract. It uses the tabula recta and works the same as Autokey.

Example:

Using a quote from George Orwell's 1984: 'If you want to keep a secret, you must also hide it from yourself.' as the key on the message INFORMATION LEAKED. COVER TRACKS:

IFYOUWANTTOKEEPASECRETYOUMUS
INFORMATIONLEAKEDCOVERTRACKS

Finding 'I' in the rows of the tabula recta and 'I' in the rows gives 'Q'. Continuing gives the ciphertext:

qsdcliagbhbviezevgqmikrfuoek

Vigenere and Gronsfeld ciphers

Vigenere and Gronsfeld are identical, but Gronsfeld uses a number key instead of a letter one.

There is a repeated key. The plaintext letter is then rotated the position number in the alphabet of the corresponding keyword letter. It also uses the tabula recta.

Vigenere Example:

The key-word is 'WARNING' the message is INFORMATION LEAKED. COVER TRACKS

WARNINGWARNINGWARNINGWARNING
INFORMATIONLEAKEDCOVERTRACKS

We find 'I' in the columns of the tabula, and 'W' in the rows to get the intersection 'E'.

The final ciphertext is

enwbzzgpifatrggeupwikntinkxy

Gronsfeld example:

The same message, but this time the key is the first 5 Fibonacci numbers: '11235'. This is the same as a vigenere cipher with a key of 'BBCDF'

1123511235112351123511235112
BBCDFBBCDFBBCDFBBCDFBBCDFBBC
INFORMATIONLEAKEDCOVERTRACKS

Final ciphertext:

johrwnbvltomgdpfeerafsvufdlu

# Transposition ciphers

Columnar Transposition Ciphers

Columnar Transposition is a simple and easy to use cipher. However, it is rather weak and easy to break.

The plaintext is written in a rectangle reading across the rows. The keyword is written across the top so each column has a letter assigned to it.

The columns are then rearranged in alphabetical order, and the text is read down the columns to form the ciphertext.

Example:

We have the message INFORMATION LEAKED. COVER TRACKS. The key is "FOUND"

There are two cases: regular and irregular.

In the regular case, the rectangle is padded out using rare characters, so it easier for the recipient to decode. Here we will use 'x' as the null character:

F O U N D
---------
I N F O R
M A T I O
N L E A K
E D C O V
E R T R A
C K S X X

Now the columns are ordered alphabetically:

D F N O U
---------
R I O N F
O M I A T
K N A L E
V E O D C
A E R R T
X C X K S

And the text is read down the columns to give the ciphertext:

rokvaximneecoiaorxnaldrkftects

In the irregular case there is no padding, which makes it harder to decrypt:

D F N O U
---------
R I O N F
O M I A T
K N A L E
V E O D C
A E R R T
C   K S

The ciphertext is the same just minus the null characters. However, it is harder to decrypt because the number of characters in the ciphertext is not a multiple of the characters in the key, so it is unknown which columns contain more characters.

Rail fence cipher

This cipher is very easy, and extremely simple to crack.

The plaintext is written in a zig-zag pattern along a number of 'rails' (the number of rails is the key). The ciphertext is obtained by reading across the 'rails'

Example:

We have the message INFORMATION LEAKED. COVER TRACKS, and a key of 4.

The plaintext is then written on 4 rails like so:

i . . . . . a . . . . . e . . . . . o . . . . . a . . .
. n . . . m . t . . . l . a . . . c . v . . . r . c . .
. . f . r . . . i . n . . . k . d . . . e . t . . . k .
. . . o . . . . . o . . . . . e . . . . . r . . . . . s

The ciphertext can be found be reading across the rails, top down:

iaeoanmtlacvrcfrinkdetkooers

Route ciphers

The route cipher can vary in difficulty to break. Badly chosen keys can leave whole words in the ciphertext, or words reversed making it very simple and easy to crack. However, a good key can leave the ciphertext a complete jumble. The plaintext is written in a rectangle reading down the columns. The ciphertext is formed by going round the rectangle in a certain fashion, described in the key.

Example:

Using the INFORMATION LEAKED. COVER TRACKS and the key 'start bottom right, spiral inwards in an anticlockwise fashion' we form the following rectangle:

I R I E D E A
N M O A C R C
F A N K O T K
O T L E V R S

And using the key, we start on 's' (the bottom right letter), move anticlockwise around the outside and when we reach 'r' we move inwards to 't' and spiral again. We get the ciphertext

skcaedeirinfotlevrtrcaomankot

You can see that is not the strongest key, because this key leaves 'info' unmoved, which can give someone an indication of the way to crack it.