Introduction to Cryptography @ Coursera

A cheat sheet

This cheatsheet wants to provide an overview of the concepts and the used formulas and definitions of the »Introduction to Cryptography« online course at coursera.

Last changed:

Week 1

Notes on Notation

Note that both $\leftarrow$ and $:=$ are used as assignments. However, $\leftarrow$ denotes assignments where subsequent execution of the right side might not yield the same result, meaning it is possibly randomized. $:=$ is used for deterministic assignments. $=$ is used for mathematical equality.

Overview of Modular Arithmetic

Introduction

Private-key Encryption

For a message space $M$ the private key encryption scheme is defined by a number of algorithms:

Any encryption scheme is required to satisfy the following correctness requirement: $\forall m \in M$, $k$ given by $\text{Gen}: \;\;\; \text{Dec}_k(\text{Enc}_k(m)) = m$

Example: The Shift Cipher

Considering the encryption of english text (only lower case characters). a is associated with $0$, b with $1$ and so on. $k \in \{1,2,…,25\}$. To encrypt using the key $k$, shift every letter of the plaintext message by $k$ positions (with wraparound). Decryption is just the reverse operation.

More formally, the scheme can be defined as:

Note that the scheme is not safe as an attacker can simply try all possible keys. This assumes however, that the attacker does know which scheme was used in the first place.

Definition: Kerckhoff's Principle

The encryption scheme itself is not secret. The only secret is the key which must be chosen at random and kept secret. This principle is subject to controversion. Arguments in favor of this principle however include that it is easier to change the key than to change the algorithm, that it is easier to keep the key secret than the algorithm for two participators. Additionally it is easier to deploy and its open approach leads to public validation if the algorithm is known.

Definition: Sufficient Key Space Principle

A too small key space for an encryption scheme is vulnerable to exhaustive-search attacks. However, large key spaces do not guarantee security.

Example: The Vigenère Cipher

The key is now a string, not just a character. To encrypt a message the characters are shifted by the respective character of the key, which is repeated in a wrap around manner for messages longer than the key. Decryption is again just the reverse operation.

The key space for this scheme with a key size of $14$ is $26^{14} \approx 2^66$ which renders brute-force search attacks useless. The scheme however is not secure as it can be attacked differently.

Suppose a key of length 14. Then every 14th character in the ciphertext was shifted the same amount. Together with plain text letter frequencies the following algorithm can be applied:

There are better (but more complicated) attacks available for this scheme, however this attack will work for long enough Vigenère ciphers.

Breaking the Vigenère Cipher

Variant Vigenère Cipher

An alternative variant of the cipher views the message as ASCII plaintext and the ciphertext as hex. This way it supports arbitrary letters (punctuation and capitals). Instead of modulo we can use XOR.

The key is a string of bytes. The plaintext is a string of ASCII chars. To encrypt, XOR each character in the plaintext with the next character of the key, which is wrapped around as needed. Decryption again just is the reverse process.

Example
Attacking the Variant Cipher

Basically we need two steps:

Determining the Key Length

Let $p_i$ (for $0 \leq i \leq 255$) be the frequency of byte $i$ in plaintext (English text)

If the key length is $N$ then every $N$th character of the plaintext is encrypted using the same shift. If we take every $N$th character and calculate frequencies, we should get the $p_i$'s in permuted order. If we take every $M$th character ($M$ not a multiple of $N$) and calculate frequencies, we should get something close to uniform. In this case $M$ can be dismissed as the key length because it is not a permutation of the frequencies of english text.

To distinguish these two, compute $\sum q_i^2$ for some candidate distribution $q_0, …, q_{255}$. If it is close to uniform it is roughly $\frac{1}{256}$. If it is a permutation of $p_i$, then $\sum q_i^2 \approx \sum p_i^2$ and it will be much larger than $\frac{1}{256}$.

In order to find the key length we compute $\sum q_i^2$ and choose the maximum value for a candidate length.