LESSON ACTIVITIES FOR

Block 3: Compression & Encryption and Block 4: Computers & Assembly Language Programming

Lesson 1 activities

Activity 1.1

Fill in this table to help you see what a difference compression makes to file size.
File A / File B / File C
How many characters does the file contain?
What type of content does the file contain?
What is its file size before compression?
What is its file size after compression?
What is its compression ratio (decompressed size/compressed file size)?
Which file compresses the most? Explain why.

Activity 1.2

Your teacher is going to read out a series of binary numbers.The first pair of binary numbers represents a colour code as follows:

00 = blue

01 = white

10 = yellow

11 = green

The second set of binary numbers represents the run length of the colour.So, for example, 00, 1101 represents 13 blue pixels.

Assuming each of the squares in the grid below represents one pixel, listen to the series of binary numbers and shade the squares.The first line of pixels has been done for you.

Line 1:000001010011001100

Activity 1.3 (homework)

  • Use four different colours to “draw” an image in the grid below.
  • Now encode the image using a 2-bit binary number to represent the colour depth and a 4-bit binary number to specify the run length of the pixels to be filled with that colour.

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
Line 13
Line 14
Line 15
Line 16

Lesson 2 activities

Activity 2.1

Use the image you encoded for your homework to complete these calculations.

How many bytesare required to represent the uncompressed file?
Remember: number of squares in grid x 2 / 8
How many bytesare required to represent the RLE encoded file?
Remember: number of codes x number of bits in each code / 8
How much storage space have you saved?

Extension

Imagine that an image:

  • contains 1,024 pixels (a grid of 32 pixels by 32 pixels)
  • contains 255 different colours (represented by 8 bits)

The image has been encoded using RLE, producing 116 binary codes comprising 8 bits (to represent the 255 colours) and 5 bits (to represent the colour run length).

Using this information, calculate:

How many bytes are required to represent the uncompressed file?
How many bytes are required to represent the RLE encoded file?
How much storage space have you saved?

Activity 2.2

Use theRun Length Encoding Calculatorto encode these text strings.
Text string / Answer
AAAABBBBBBBBBCADDDDEEFFFFFFFF
ABCABCABCABCABCABCABCABCABCS
BBGGYYAACCFFEEBBGGYYAACCFFEE
Which one compresses the most?
Why is this?
Describe in English the process the RLE calculator follows to encode a piece of text.

Activity 2.3

An RLE compression algorithm works by removing repeated data and replacing it with a number representing the run length of that item.

  • Fill in the gaps to complete this algorithm.

1. Start with the first character in the string.

2. Write down the number 1.

3. Compare the first character with the next character on the right.

4. If they are the same, ______.

5. If they are not the same, ______.

6. Move on to the next character on the right.

7. Go back to step 2 and repeat until you reach the end of the string.

8. ______.

  • Test out the algorithm using these data strings:
  • AAAABBBBBBBBBCADDDDEEFFFFFFFF
  • ABCABCABCABCABCABCABCABCABCS
  • BBGGYYAACCFFEEBBGGYYAACCFFEE

Activity 2.4(homework)

Write a program in Python to implement the RLE compression algorithm you completed in Activity 2.3.

Activity 2.5(extension)

Write a program in Python to decode a file compressed using RLE compression.

Lesson 3 activities

Activity 3.1

The wheels on the bus go round and round, round and round, round and round.
The wheels on the bus go round and round all day long.
How many characters, including spaces and punctuation marks, are there in this song?
Assuming one byte is used to represent each character, what is its file size?
Complete this table.
Word / Number of times used / Number of bytes in word
The / 2 / 3
wheels / 2 / 6
on / 2 / 2
the / 2 / 3
bus
go
round
and
all
day
long

Activity 3.2

  • Complete this lookup table of all the words used more than once in the song.

Lookup table
0. / The
1. / wheels
2. / on
3. / the
4.
5.
6.
7.
  • Use thelookup table you have completed to encode the song, replacing repeated words with the number representing their position in the table.

Activity 3.3

A lookup table has been used to encode this text:

1

Encoded text

0 1 2 3 generally more effective than 4 1 2 in reducing 5 size 6 7. However, whereas 4 2 allows 5 8 1 910 perfectly reconstructed from 5 compressed 1, 11 2 causes some 6 5 8 1 910 permanently lost.

0 1 2 3 most often 12 for media 7, i.e. music, pictures 13 videos. This type 6 1 3 intended 9 10 12 14 humans whose brains are capable 6 ‘filling in 5 gaps’ created 14 11 2.

MP3 uses 11 1 2 9 compress audio 7 for use on portable media players where space 3 limited.

PNG 13 GIF use 4 1 2 9 reduce 5 size 6 image 7.

0. / Lossy
1. / data
2. / compression
3. / is
4. / lossless
5. / the
6. / of
7. / files
8. / original
9. / to
10. / be
11. / lossy
12. / used
13. / and
14. / by

1

Decode the text.

‘Short and Sweet’

Complete the worksheet activity ‘Short and Sweet’ from Computer Science Unplugged.

‘Extra for Real Experts’

Complete the worksheet activity ‘Extra for Real Experts’ from Computer Science Unplugged.
Lesson 4 activities

Activity 4.1

Use an image editor, such as pixlr’s photo editor online, to experiment with compression. Start with an uncompressed BMP file. Fill in this table.

Original BMP image / JPEG with 100% quality
[Insert image here] / [Insert image here]
File size: / File size:
Image quality: / Image quality:
JPEG with 50% quality / JPEG with 25% quality
[Insert image here] / [Insert image here]
File size: / File size:
Image quality: / Image quality:

Activity 4.2

Use a media player such as iTunes to experiment with music compression by encoding a music file using different bit rates.

Original uncompressed WAV file / Higher quality MP3
(around 192kbps)
[Insert sound file here] / [Insert sound file here]
Sound quality: / Number of kbps:
Number of kbps: / File size:
File size:
High quality MP3
(around160kbps) / Good quality MP3
(around 128kbps)
[Insert sound file here] / [Insert sound file here]
Number of kbps: / Number of kbps:
File size: / File size:

Activity 4.3

Lossless and lossy compression summary sheet

Explain what is meant by lossless compression.
What type of data can be compressed using a lossless compression algorithm?
Describe how a lossless RLE algorithm works.
Some lossless compression algorithms use a lookup table.Explain what the lookup table is for.
Explain how lossy compression differs from lossless compression.
Explain why lossy compression is usually used for media files.
Outline the process of compressing an audio file using a lossy compression algorithm.
Outline the process of compressing a bitmap image using a lossy compression algorithm.

Lesson 5 activities

Activity 5.1

Crack this code!
WKH WUHDVXUH LV KLGGHQ XQGHU WKH SDOP WUHH

Hint: H = E and W = T

Activity 5.2

Who uses encryption and what do they use it for what?
Users of encryption / What they use encryption for
Businesses
Individuals
Governments
E-traders
The military

Activity 5.3 (homework)

Create your own cipher and then use it to encrypt a secret message.Make sure you keep a note of the key to cracking your cipher, so that you (or someone else) can decode the message later!

Lesson 6 activities

Activity 6.1

Use a Caesar cipher to decode and encode these messages.
Plain text / Shift / Encrypted text
THE ENIGMA MACHINE WAS INVENTED BY THE GERMANS / +3
COLOSSUS WAS THE WORLD’S FIRST DIGITAL COMPUTER / +4
+5 / YMJ HFJXFW HNUMJW NX FS JCFRUQJ TK WTRFS NSLJSZNYD
-3 / QEB HBV FP EFAABK RKABO QEB CILTBO MLQ

Activity 6.2

With a partner, produce a step-by-step guide to using a Caesar cipher to produce an encoded message.

Activity 6.3 (homework)

Produce a step-by-step guide to decrypting messages that have been encoded using a Caesar cipher.

Lesson 7 activities

Activity 7.1

A function caesar_cipher_encrypt has two arguments: a string ‘message’ and an integer ‘key’ and returns a string ‘encrypted_message’.

All the characters that can be encrypted are stored in a list ‘letters’.Any characters in ‘message’ that are not in list ‘letters’ cannot be encrypted.

  • Load and run the function to see for yourself what it does.First, open Activity7.1.py in IDLE, then click Run > Run Module.Once the Python shell has loaded remember that to run the function you need to call it and enter its arguments.
  • Try different messages and different keys.What happens when a message includes a character that can’t be encrypted?What happens when the character to be encrypted is a ‘z’?
  • Add comments to the Python code to explain how it works.You should add a comment after every # in the Python code.
  • Amend the function so that the digits 1–9 can also be encrypted.

Activity 7.2

  • In pairs, make a new version of the function called caesar_cipher_decryptthat decrypts text encrypted using a Caesar cipher.
  • Add comments to the Python code to explain how this function differs from the original.

Hint: The inputs to the function should be the text to be decrypted and the shift to be applied.

Hint: The function should return the decrypted message.

Activity 7.3

There is really no need to have separate functions to encrypt and decrypt messages.Produce a new function caesar_cipher that does both.

Hint: The function will need a third argument: a string ‘action’ to determine whether the message has to be encrypted or decrypted.

Activity 7.4

Write a user interface for the caesar_cipher you produced in Activity 7.3.It should ask the user to select whether they want to encrypt a message, decrypt a message or exit the program.

Lesson 9 activities

Activity 9.1

List as many different types of digital computers as you can. Look for computers both in the past as well as the present, and for objects that contain embedded computers.

Activity 9.2

Sort the things inthis list according to whether they are hardware or software.

  • Mouse
  • Computer program
  • Web browser
  • Microphone
  • CPU
  • Hard disk drive
  • Digital camera
  • Windows operating system
  • DVD drive
  • Touch screen
  • Word processor
  • Speakers
  • Spreadsheet
  • Printer
  • Mobile phone app
  • Android operating system
  • SD memory card

Hardware / Software

Activity 9.3 (homework)

Answer these questions to summarise what you have learned in this lesson.

What is a digital computer?
Define computer hardware.
Give an example of computer hardware.
Define computer software.
Give an example of computer software.

Lesson 10 activities

Activity 10.1

  • Write a computer program that asks the user to type in three numbers, adds them up and then displays the answer on the screen.
  • Explain your program using the input-process-output model.

Activity 10.2 (homework)

Select two actions you complete regularly and describe them in terms of the input-process-output model.

Examples could be:

  • Running a mobile phone app
  • Uploading an image to a social networking profile

Lesson 11 activities

Activity 11.1

Use the function to identify the hardware component.
Function / Hardware component
A temporary storage area for data and program instructions while a program is running
A microprocessor which carries out the instructions in computer programs by performing arithmetic and logic operations, and controls inputs and outputs
A persistent data storage area for data and program instructions
To provide connections to the input and output peripherals such as printers, mouse, keyboard, touch screen, speakers, networks, and so on

Activity 11.2

This diagram represents the way in which buses connect the main hardware components in a digital computer. Copy and complete the diagram using these labels:

  • CPU
  • Memory
  • Input/output devices
  • Data, control and address bus

Activity 11.3

From the function given, identify and insert the name of the correct bus.

Function / Type of bus
Sends and receives signals that control the CPU and other parts of the computer system
Carries the address of memory locations used to store data and program instructions
Transfers the binary data around the computer

Activity 11.4

Label the following on the picture of the Raspberry Pi:

  • SD card (memory)
  • CPU processor and RAM memory
  • Ethernet network connection
  • 2 USB connectors (mouse and keyboard)
  • HDMI connector for monitor
  • Audio
  • Power supply


Lesson 12 activities

Activity 12.1

Windows is an example of an operating system. List as many other operating systems as you can. Aim for a list of at least five operating systems. Discuss with other class members or use an internet search if you need to.

e.g. Windows

Activity 12.2

Assuming that the user is the outer circle, use the labels ‘hardware’, ‘application software’ and ‘operating system’ for the other circles to show the role of the operating system.

Activity 12.3

Using a non-networked computer and the operating system of your choice, do the following:

  • make a hierarchy of directories and files
  • remove files and directories
  • rename files and directories
  • change the current working directories
  • view the current working directory.

Here is a list of useful Raspbian (Unix) and Command Line Interpreter (LX Terminal) file and directory commands.

Commands / Function
pwd / Print working directory – display the current directory
cd directory / Change directory
mkdir directory / Make a new directory
rm file / Remove a file
touch file / Create a new empty file
cat file / Catalogue a file – list the contents of a file
ls -l / List the files in the current working directory displaying all the details about the files

Activity 12.4

  • Bring up the task manager in whatever operating system you are using (in Windows, control/alt/del).
  • Find the networking information within the task manager (in Windows, choose the networking tab).
  • What happens when the user accesses the network, for example by opening a web page or accessing information on a server?

Activity 12.5

  • Bring up the task manager in whatever operating system you are using (in Windows, control/alt/del).
  • Find the user information within the task manager (in Windows, choose the user tab).
  • List the users who are using your computer. What information can you find out about them?

Lesson 13 activities

Activity 13.1

  • Open up the operating system’s task manager (in Windows, control/alt/delete) and find the list of applications running (in Windows, choose the Applications tab).
  • Now find the information on the processes running (in Windows, choose the Processes tab).Scroll up and down the list to see how many processes it takes to run the operating system and any applications you currently have open.
  • Now open up a few applications, e.g. a web browser, word processor, spreadsheet software, a graphics package.
  • Answer these questions:
  1. What happens to the list of applications?
  2. What happens to the number of processes running on the computer?
  3. Try to explain why there are more processes running than applications running.

Activity 13.2

Your teacher will run this activity. The instructions are here for information only.

Process scheduling – an “unplugged” activity to simulate the scheduling of processes

Requirements

  • Large stick notes
  • White board
  • Two tables
  • Area for process queue
  • Stop watch
  • Pens
  • Two students who represent the operating system (“OS1” will allocate the process ID and time slots, “OS2” will send the next process to the CPU)
  • One student who represents the “CPU”
  • One student who represents the “user” who is running the programs
  • Sixteen other students who represent the programs and applications and who will be the “processes” (just add more programs/applications depending of number of students in group)

Starting positions

  • The “CPU” should sit at a table with a pen and stop watch.
  • “OS1” needs a pen and an empty process table drawn on a whiteboard (add more rows as required:

Process ID / Name of program or application
  • Allocate a queue area where the “processes” will stand in order while they wait to be “executed” after they have been allocated a process ID.
  • The “user” sits at table with a pen and sticky notes.

Running the programs

  • The “user” starts by writing on a sticky note the name of a program or application, in the order given in the table below. The “user” must write program and application names in the same order as they appear in the table below.

Word processor
Web browser
Sound program
Myprog.py
Sort.py
Word processor
Myprog.py
Spreadsheet
Sort.py
Word processor
Spreadsheet
Web browser
Sound program
Web browser
Sound program
Sort.py
  • The “user” hands the sticky note on which he/she has written a program or application name to a student who will be that “process”.
  • The “process” goes to “OS1” who allocates the next free process ID from the process table. “OS1” also allocates the correct number of time slots needed to complete the process, according to the table below:

Type of process / Time slots
word processor / 1 2 3
myprog.py / 1 2
sort.py / 1
spreadsheet / 1 2 3 4
web browser / 1 2 3
sound program / 1 2 3 4 5
  • So, if the “process” hands “OS1” a sticky note that says “Word processor”, “OS1” adds a process ID and three time slots “1, 2, 3” to the stick note and hands it back to the “process”. “OS1” must also update the process table on the whiteboard.
  • The “process” joins the back of the queue holding up their sticky note.
  • “OS2” is constantly looking at the queue waiting for a process with a process ID. They send the “process” at the top of the queue to the “CPU” table.
  • Each “process” gets 10 seconds to execute with the “CPU” – when the “process” arrive at the table, “CPU” starts the stop watch, crosses one time slot off the sticky note and then says “Time’s up” after 10 seconds. At this point, the “process” must return to the back of the queue.
  • The “process” should check their sticky note. If all their time slots have been crossed off, they should shout their process ID and “Finished” and then sit down.
  • When “OS1” hears that a process has finished, they should remove that process from the process table
  • If the “process” still has time slots left they go to the back of the queue.
  • Repeat until all the processes have finished.

Alternatives