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

Preview

AC 8.3: Scrambling data: hash, one key, two 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

An analyst sends a customer file to a partner over the internet. A postcard can be read by anyone who handles it. A locked box opens 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.

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.

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.

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.

Hashing makes a fingerprint

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 that 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 % 997

print(simple_hash("survey"))
print(simple_hash("survey"))
print(simple_hash("surveys"))

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

Symmetric encryption uses one key

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 of survey files.

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("SALES", 3)
print(secret)
print(shift_text(secret, 23))

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

Asymmetric encryption uses two keys

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 file 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, and 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.