# Block Ciphers

A block cipher is an encryption scheme which converts the plaintext into chunks (or blocks) of a fixed length and encrypts each chunk individually.

Security in block ciphers is based upon a complex function with a short, fixed size key rather than a complex, changing key.

## Basic building blocks

Block ciphers are generally created by composing a set of functions
that produce *transposition* and *substitution*.

### Transposition

Transposition simply moves symbols around inside the plaintext. A
transposition-only cipher would contain all of the same symbols as
the plaintext but in a different order. Transposition is useful as
it provides *diffusion* in the encryption scheme. This means that
underlying structures of the plaintext (English words for instance)
are hidden by moving parts of the structure to different places.

### Substitution

Substition turns symbols into different symbols in a reversible manner.

The most basic substitution is a mapping from your alphabet

More complex substitutions will change a symbol to different symbols
depending on other factors (such as the position of the symbol in the
text or the symbol that was before it). Such substitutions are known as
polyalphabetic because they convert from your alphabet

### Product Ciphers

Given reversible (bijective) ciphers (transposition and substitution)
one can easily produce compound or *product* ciphers by simple function
composition.

This works because the composition of two bijections is also a bijection.

If our encryption function

## Block cipher modes

With a given block cipher with encryption function

### Electronic Codebook Mode (ECB)

The most basic and obvious mode is to just use the function as-is; encryption of each block is independent of other blocks. Apparently it is insecure in obvious ways.

### Cipherblock Chaining Mode (CBC)

Each plaintext block *initialisation vector* to act as the initial
ciphertext.

where

### Output Feedback Mode (OFB)

In OFB mode the encryption function is never applied directly to the plaintext; rather it is repeatedly applied to itself (with an initialisation vector) and the output of that is XORed with a block of plaintext.

This is a method for using a block cipher encryption function as the keystream generator for a Vernam Cipher.

where

It is important to note that

### Cipher Feedback Mode (CFB)

Similarly to OFB: CFB uses the encryption function to generate a keystream for a Vernam Cipher.

It differs in that it uses ciphertext from the previous block as the input to the encryption function at each iteration, rather than the previous block of keystream.

As with OFB, CFB will need an initialisation vector.

## The Feistel Principle

The Feistel principle allows us to construct ciphers so that the same
circuit is used for both encryption and decryption. Given an encryption
function

Note that this will require

The decryption operation is simply running through the encryption with the keys in reverse order, but is written in the slides as: