Introduction to Cryptography¶
Learning Goals¶
After this week, you will be able to
- Understand what cryptography is, why we need it, and where it is used
- Explain the difference between symmetric and asymmetric ciphers
- Explain the basic idea behind the Diffie-Hellman key exchange
- Understand what hashing is and how it differs from encryption
- Lecture slides: PDF
Preparation¶
What is cryptography?¶
Cryptography is the process of coding information so that we can achieve properties such as confidentiality (through symmetric or asymmetric encryption) or authenticity (through digital signatures or message authentication codes). Note that cryptography also covers many other aspects of protecting information, but we will mainly focus on these properties for now.
Encryption¶
Encryption is a key part of cryptography. It changes plan text information into a secret code called a ciphertext to keep it confidential.
It does this using an algorithm called a cipher and a secret value called a key. Thus, without knowing the key, you can not decrypt the ciphertext or learn anything about the encrypted plantext message.
Symmetric Encryption¶
In symmetric encryption (also known as secret-key encryption), the same key is used for both encryption and decryption (this is the symmetry). In the picture below, you can see a plaintext being encrypted with a secret key, resulting in a ciphertext. The ciphertext can then be decrypted using the same secret key, yielding the same plaintext we started with.

A classic Cipher - The Caesar Cipher¶
Classical ciphers form the historical foundation of modern cryptography. The Caesar Cipher is a simple substitution cipher in which each letter is shifted by a secret number of positions.
Watch the following video to learn how this works:
Asymmetric Encryption¶
In asymmetric encryption (also known as public-key encryption), the encryption key is different from the decryption key. You will have one key for encryption (the public key) and another one for decryption (the secret key). The idea is that everyone can encrypt a message, but only the correct recipient can decrypt it.

The following video explains asymmetric encryption in a simplified way, as well as its usage:
Hashing¶
Hashing is a way to create a fingerprint of some information, it being a short text like "ABC" or a file of many GBs. The hash function always output a string of a fixed size (for example 256 bits) no matter the input, and it is deterministic such that the same input always produce the same output.
Hash functions has some important security properties: 1) they are supposed to be one-way, so that the output looks random and it is hard to find out what was the input to the functions, and 2) they should be collosion resistant, meaning that it should be hard to find two different values x and y such that the hashes h(x) and h(y) are equal.
Optional Material¶
If you find cryptography to be an interesting topic, we recommend having a look at the book Serious Cryptography by Jean-Philippe Aumasson.
A crash course video containing several of the elements covered in the preparation material, as well as some other interesting parts:
Teamwork¶
For this week’s lab, you will be using Jupyter Notebook to complete both the tasks and your report. The notebooks are available under the following links:
Be sure to read through all the instructions carefully so you do not miss any tasks or important information. Questions that require reflection are highlighted with a text box like the one below, where you will enter your answers:
Question 4.1.1.1: Explain what the function does at each line
Report¶
Once you have completed the lab, export the notebook (with all your answers and changes), and make it an attachment to Report 3 to be uploaded to Blackboard for evaluation. You also have to include a reflection note about the lab in the report.