Intro to Cryptography
Why study cryptography?
Speaking the same language
A Shannon cipher is a pair of functions: \(\mathcal{E} = (E, D)\)
\mathcal{E} in \(\LaTeX{}\)The encryption function \(E\) takes as input a key \(k\) and a message \(m\), and produces as output a ciphertext \(c\).
The decryption function \(D\) takes as input a key \(k\) and a ciphertext \(c\), and produces a message \(m\).
The correctness property states that decryption reverses encryption for all \(k\) and \(m\).
Codes through the ages
encrypt(plaintext: str, shift: int) -> ciphertextdecrypt(ciphertext: str, shift: int) -> plaintext0x00 half the time and spread the rest thinly.zip shrinks text files so well![citation needed]
^ in most programming languages, \oplus in \(\LaTeX{}\)^ operator or the operator.xor() function.bin(), oct() and hex() for readability.0b, 0o and 0x for binary, octal and hexadecimal literals.XOR is associative:
XOR is commutative:
Test this out on paper or in code!
Any bit XOR itself is always 0 (self-inverse):
XORing any bit with 0 has no effect (identity element):
Test this out in Python!
That XOR tangent wasn’t just for fun!
Let \(\mathcal{E} = (E, D)\) be a Shannon cipher defined over \((\mathcal{K}, \mathcal{M}, \mathcal{C})\). Consider a probabilistic experiment in which the random variable k is uniformly distributed over \(\mathcal{K}\).
If for all \(m_0, m_1 \in \mathcal{M}\), and all \(c \in \mathcal{C}\), we have
\[\Pr[E(\mathbf{k}, m_0) = c] = \Pr[E(\mathbf{k}, m_1) = c]\]
then we say that \(\mathcal{E}\) is a perfectly secure Shannon cipher.
For example, we’d have:
So what’s the problem here? We (and Eve) still can’t read the ciphertexts…
Not perfect, but good enough?
What did we learn?
Ask now, catch me after class, or email eoin@eoin.ai
© 2026 Eoin O’Brien. All rights reserved.