Question bank › A-level Computer Science › Fundamentals of data representation

Data compression and encryption

Answer on paper first, then reveal the mark scheme one mark at a time.

1Core3 marks

A Caesar cipher replaces each letter with the letter a fixed number of places further along the alphabet, wrapping round from Z to A. Spaces are left unchanged.

(a) State what is meant by the term ciphertext. [1]

(b) Encrypt the plaintext HARBOUR using a Caesar cipher with a shift of 5. [1]

(c) The ciphertext ZRRG NG ABBA was produced with a shift of 13. Decrypt it. [1]

2Core4 marks

The diagram shows a 12 × 5 monochrome bitmap image. Each pixel is either white (W) or black (B).

The image is compressed using run-length encoding (RLE), storing each run as a frequency followed by a colour, e.g. 5W.

(a) Give the RLE for Row 3. [1]

(b) Give the RLE for Row 4. [1]

(c) Explain why using RLE on Row 5 would not reduce the amount of data stored. [2]

Row 1Row 2Row 3Row 4Row 5
3Standard4 marks

A Vernam cipher is used to encrypt the single character K, whose 8-bit ASCII code is 01001011.

The key for this character is 11010110.

(a) Calculate the 8-bit ciphertext. Show your working. [2]

(b) Show how the recipient obtains the plaintext from the ciphertext. [1]

(c) State one requirement of the key, other than being used only once, needed for the Vernam cipher to have perfect security. [1]

Stuck on Data compression and encryption?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Standard5 marks

A dictionary-based compression method replaces each word in a message with its index in a dictionary. Spaces are not stored in the compressed data because every word is separated by a single space.

The message is:

RED CAR RED VAN BLUE CAR RED VAN

The dictionary is:

IndexWord
0RED
1CAR
2VAN
3BLUE

(a) Give the compressed message as a sequence of indices. [1]

(b) The uncompressed message is stored using 8-bit ASCII, including the spaces. Calculate its size in bits. [1]

(c) Each index is stored using the minimum number of bits. The dictionary must be sent with the data, with each letter of each word stored in 8-bit ASCII (ignore any separators). Calculate the total size of the compressed data plus dictionary, in bits. [2]

(d) Explain why dictionary-based compression usually achieves a greater saving on longer files. [1]

5Standard4 marks

Four files were compressed and then decompressed. The table shows the results.

FileContentsOriginal sizeCompressed sizeDecompressed file identical to original?
Asong.wav42.0 MB3.8 MBNo
Bgame.py (source code)96 KB31 KBYes
Cscan.bmp6.0 MB1.5 MBYes
Dclip.mov250 MB40 MBNo

(a) Identify the files that were compressed using lossy compression. [1]

(b) Calculate the percentage reduction in size for file C. [1]

(c) Explain why lossy compression would not be appropriate for file B. [2]

6Hard4 marks

A monochrome bitmap image is 64 pixels wide and 48 pixels high. Uncompressed, each pixel is stored using 1 bit.

The image is compressed using run-length encoding. Each run is stored in one byte: 1 bit for the colour followed by a 7-bit unsigned integer for the run length.

(a) Calculate the size of the uncompressed image in bytes. [1]

(b) After compression the image is stored as 150 runs. Calculate the percentage reduction in file size. Give your answer to 1 decimal place. [2]

(c) One part of a different image contains 300 consecutive white pixels. State the minimum number of runs needed to store these pixels. [1]

7Hard4 marks

A messaging app currently encrypts data using a cipher whose security relies on computational security. A developer suggests replacing it with the Vernam cipher.

Compare the security provided by the Vernam cipher with that provided by ciphers that rely on computational security. [4]

8Standard4 marks

An attacker intercepts the following message, which was encrypted using a Caesar cipher (spaces were left unchanged):

UNJEN CQN PJCN XYNW

The attacker knows that the plaintext begins with the word LEAVE.

(a) Determine the shift used and decrypt the whole message. [2]

(b) Explain why the attacker could have decrypted the message even without knowing any of the plaintext. [2]

9Stretch4 marks

Two 2-character messages, P1 and P2, were encrypted with a Vernam cipher, but by mistake the same key was used for both. The ciphertexts are:

C1 = 11110010 00100011
C2 = 11111101 00100101

An attacker discovers that P1 is GO. The ASCII code for A is 65 (01000001) and letters are in alphabetical order.

(a) Recover the key, showing your working. [2]

(b) Use the key to find P2. [1]

(c) Explain why reusing the key compromised the security of the cipher. [1]

10Stretch5 marks

The algorithm below performs run-length encoding on a string. Strings are indexed from 0 and + concatenates strings.

Text ← "KKKZZWWWW"
Output ← ""
Count ← 1
FOR i ← 1 TO LEN(Text) - 1
  IF Text[i] = Text[i - 1] THEN
    Count ← Count + 1
  ELSE
    Output ← Output + INT_TO_STRING(Count) + Text[i - 1]
    Count ← 1
  ENDIF
ENDFOR
Output ← Output + INT_TO_STRING(Count) + Text[LEN(Text) - 1]
OUTPUT Output

(a) Complete a trace table with columns i, Text[i], Count and Output, showing the values at the end of each iteration of the FOR loop, and state the value that is output. [3]

(b) When the same algorithm is run on the string "111222" it outputs "3132". Explain why this is a problem, and suggest how the output format could be changed to fix it. [2]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session