Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

SC 8.3: Hashing, symmetric and asymmetric keys

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

55 minutes

A postcard or a locked box

A postcard can be read by anyone who handles it. A locked box can be opened only with the key.

Data crossing the internet is like a postcard unless it is scrambled.

Today you meet three ways to scramble or fingerprint data, and learn when to use each.

By the end of this lesson

Note

I can tell apart three ways to scramble or fingerprint data and say when each one is used.

Key words

WordWhat it means
EncryptionScrambling data so only someone with the right key can read it.
PlaintextData before it is scrambled.
CiphertextData after it is scrambled.
KeyA secret value used to scramble or unscramble data.
HashingTurning data into a short fixed fingerprint. It cannot be turned back.
Symmetric encryptionEncryption where the same key locks and unlocks.
Asymmetric encryptionEncryption with a pair of keys: a public key locks and a private key unlocks.
Public keyThe key you share with everyone.
Private keyThe key you keep secret.
Digital signatureA mark made with a private key that proves who sent a message.

The cells students fill in are left blank in this preview.

Starter: what you already know

Have a go

Starter: what you already know

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Cycle 1: hashing

Hashing turns any data into a short fingerprint of fixed size. The same data always gives the same hash. A tiny change gives a very different hash.

You cannot turn a hash back into the data.

Purpose: store passwords and check data has not changed. A site keeps the hash of your password, not the password. At login it hashes what you type and compares.

Try it: a toy hash

Code: python
def simple_hash(text):
    total = 0
    for letter in text:
        total = total + ord(letter)
    return total % 1000

print(simple_hash("cat"))
print(simple_hash("cat"))
print(simple_hash("cot"))

# Same input, same hash. A change gives a new one.
# This toy is NOT safe. Real hashes are far stronger.

Cycle 2: symmetric encryption

Symmetric encryption uses one key to lock and the same key to unlock.

It is fast, so it suits large amounts of data such as a whole disk or a video call.

The problem: both sides must have the key. How do you send the key safely? If a thief sees the key, all is lost.

Try it: a toy symmetric cipher

Code: python
def shift_text(text, key):
    result = ""
    for letter in text:
        if letter >= "A" and letter <= "Z":
            result = result + chr((ord(letter) - 65 + key) % 26 + 65)
        else:
            result = result + letter
    return result

secret = shift_text("HELLO", 3)
print(secret)
print(shift_text(secret, 23))

# Locking with 3 and unlocking with 23 uses the same idea.

Cycle 3: asymmetric encryption

Asymmetric encryption uses a pair of keys. The public key locks. Only the matching private key unlocks.

Sam shares a public key with the world. Anyone can lock a message for Sam. Only Sam, with the private key, can read it.

It is slower, but it solves the sharing problem. It also gives digital signatures: sign with the private key, anyone can check with the public key.

The lesson goes on

9 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.