AQA A-Level Computer Science Paper 1, June 2025: Question 4

13 marks · Hard difficulty · Programming

Write a program that uses a transposition cipher to encrypt a user-entered string into a specified number of columns, ignoring non-alphabetic characters, and provide test evidence.

Practise this question

Question

Question 04 asking students to write a program implementing a columnar transposition cipher. Characters are written into a grid row by row (left to right, top to bottom) and read column by column (top to bottom, left to right). Non-alphabetic characters are removed. Three examples are given with grids showing how 'hypothetically' is encrypted with 3 and 5 columns, and 'How many, how rarely?' with 4 columns. Part 04.1 requires the program source code (12 marks), and part 04.2 requires a screenshot showing test execution with 'Hello there, are you ok?' and 4 columns (1 mark).
Question text

04 Write a program that uses a transposition cipher to encrypt a string entered by the

user.

After the user enters the string to encrypt, they enter the number of columns to use.

Different numbers of columns result in different encrypted versions of the same string.

Any non-alphabetic characters in the string entered by the user are ignored and will

not appear in the encrypted text.

To encrypt the string, the characters from the user’s input are written into a grid (left to

right, top to bottom) of cells which has the number of columns specified by the user.

The characters are then read from the grid in a different order (top to bottom,

left to right).

Example 1

If the user enters the string hypothetically and 3 for the number of columns,

then the encrypted version of that string will be hoeclyttayphil

h y p

o t h

e t i

c a l

l y

Example 2

If the user enters the string hypothetically and 5 for the number of columns,

then the encrypted version of that string will be hhayelptloiytc

h y p o t

h9 e t i c

a l l y

Example 3

If the user enters the string How many, how rarely? and 4 for the number of

columns, then the encrypted version of that string will be Haoronwewyrlmhay

H o w m

a n y h

o w r a

r e l y

The spaces and punctuation characters have been removed in the encrypted string.

Evidence that you need to provide

Include the following evidence in your Electronic Answer Document.

04.1 Your PROGRAM SOURCE CODE.

[12 marks]

04.2 SCREEN CAPTURE(S) showing the results of testing the program by entering the

string:

Hello there, are you ok?

and 4 for the number of columns.

[1 mark]

Section C

You are advised to spend no more than 20 minutes on this section.

Enter your answers to Section C in your Electronic Answer Document.

You must save this document at regular intervals.

These questions refer to the Preliminary Material and the Skeleton Program, but do not require

any additional programming.

Refer either to the Preliminary Material issued with this question paper or your electronic copy.

Mark scheme

Show the mark scheme Mark scheme for Question 04. Question 04.1 has a 4-level rubric totaling 12 marks (4 for design, 8 for programming), ranging from Level 1 (1–3 marks) to Level 4 (10–12 marks for a fully working solution that meets all requirements). Question 04.2 awards 1 mark for a screen capture showing input 'Hello there, are you ok?' and grid size 4 displaying the expected ciphertext 'Horeoeteyklhaoleru'.

Question Marks

04 1 4 marks for AO3 (design) and 8 marks for AO3 (programming) 12

Mark Scheme

Mark

Level Description

Range

4 A line of reasoning has been followed to arrive at a 10–12

logically structured working or almost fully working

programmed solution that meets most of the

requirements. All of the appropriate design decisions

have been taken. To award 12 marks, all of the

requirements must be met.

3 There is evidence that a line of reasoning has been 7–9

followed to produce a logically structured program. The

program displays relevant prompts, inputs the required

data, has at least one iterative structure and at least one

selection structure and uses appropriate variables to

store most of the needed data. An attempt has been

made to test for alphabetic/non-alphabetic characters,

although this may not work correctly under all

circumstances. The solution demonstrates good design

work as most of the correct design decisions have been

made.

2 A program has been written and some appropriate, 4–6

syntactically correct programming language statements

have been written. There is evidence that a line of

reasoning has been partially followed as, although the

program may not have the required functionality, it can

be seen that the response contains some of the

statements that would be needed in a working solution.

There is evidence of some appropriate design work as

the response recognises at least one appropriate

technique that could be used by a working solution,

regardless of whether this has been implemented

correctly.

1 A program has been written and a few appropriate 1–3

programming language statements have been written,

but there is no evidence that a line of reasoning has been

followed to arrive at a working solution. The statements

written may or may not be syntactically correct. It is

unlikely that any of the key design elements of the task

have been recognised.

– A-LEVEL COMPUTER SCIENCE – –

04 2 Mark is for AO3 (evaluate) 1

**** SCREEN CAPTURE ****

Must match code from 04.1, including messages on screen capture(s) matching

those in code.

Code for 04.1 must be sensible.

Screen captures showing the correct user inputs with the expected string being

displayed;

How to answer it

Transposition Cipher Algorithm & Testing

📌 What this question tests

This Paper 1 programming task assesses AO3 (Design, Implementation, and Evaluation). Specifically, you must demonstrate the ability to:

  • Filter string inputs by removing punctuation and whitespace while retaining letter case.
  • Implement transposition cipher logic (writing horizontally across columns and reading vertically down columns).
  • Handle jagged/incomplete grid boundaries without causing "index out of range" exceptions.
  • Provide matched validation testing evidence with exact input/output alignment.

Question 04.1 — Program Source Code

12 Marks (4 marks AO3 Design, 8 marks AO3 Programming)

✅ Model Solution (Python 3)

This implementation uses string step-slicing to traverse columns without needing an explicit 2D matrix:

# 1. Inputs raw_text = input("Enter the text to encrypt: ") num_cols = int(input("Enter the grid size: ")) # 2. Filter non-alphabetic characters (keep case) cleaned_text = "" for char in raw_text: if char.isalpha(): cleaned_text += char # 3. Read down each column in order ciphertext = "" for col in range(num_cols): for i in range(col, len(cleaned_text), num_cols): ciphertext += cleaned_text[i] # 4. Output the result print(ciphertext)

💡 Key Knowledge: Two Core Techniques

  • Sanitisation: Non-alphabetic characters are filtered using char.isalpha() (or checking ASCII ranges 65–90 and 97–122 ). Note: Do not force lower-case; original casing must be kept.
  • Column Traversal: Writing row-by-row into C columns means that elements in the same column are exactly C positions apart in the 1D string.
    For column col , indices are:
    col, col + C, col + 2C, ... < len(text)

📐 Step-by-Step Logic Trace (Example 1)

Input: hypothetically , Columns = 3

h (0)y (1)p (2)
o (3)t (4)h (5)
e (6)t (7)i (8)
c (9)a (10)l (11)
l (12)y (13)
  1. Col 0: indices 0, 3, 6, 9, 12 → h, o, e, c, l
  2. Col 1: indices 1, 4, 7, 10, 13 → y, t, t, a, y
  3. Col 2: indices 2, 5, 8, 11 → p, h, i, l
  4. Combined: hoeclyttayphil

❌ Common Student Pitfalls

  • Modifying Case: Calling .lower() on the entire string loses the capital letters shown in Example 3 and the 04.2 test.
  • Padded Grid Traps: If populating a 2D array and padding unused cells with spaces, students often forget to strip out spaces when reading back, appending unwanted spaces to the output.
  • Index Errors: Using nested loops based on a fixed rectangular row-count instead of checking index < len(cleaned_text) leads to IndexError: string index out of range .
Mark Scheme Levels Breakdown (AO3):
  • Level 4 (10–12 marks): Fully structured, working or almost fully working solution meeting all specifications, robust data validation of alphabetic characters, and accurate transposition.
  • Level 3 (7–9 marks): Clear logical flow, working prompt/inputs, correct iterative and selection constructs, partially successful character filter.
  • Level 2 (4–6 marks): Some syntactically correct code matching problem requirements, but missing complete transposition logic.

Question 04.2 — Screen Capture Test Evidence

1 Mark (AO3 Evaluate)

✅ Expected Screen Capture

Your screenshot must show the program running with the exact inputs and outputs:

Enter the text to encrypt: Hello there, are you ok? Enter the grid size: 4 Horeoeteyklhaoleru

🧠 Exam Technique & Examiner Rules

  • Strict Match Requirement: The prompts shown in your screenshot (e.g. Enter the text to encrypt: ) must exactly match the prompt strings in your source code from 04.1.
  • Sensible Code Prerequisite: The 1 mark for the screen capture is only awarded if the code in 04.1 is sensible and generated the output honestly.
  • Verification:
    Cleaned text = Hellothereareyouok (18 characters).
    Col 0: H, o, r, e, o → Horeo
    Col 1: e, t, e, y, k → eteyk
    Col 2: l, h, a, o → lhao
    Col 3: l, e, r, u → leru
    Output = Horeoeteyklhaoleru
Mark Scheme Guideline: Award 1 mark for screen capture showing the correct user inputs with the expected string displayed ( Horeoeteyklhaoleru ).

Topics

4.1 Fundamentals of programming · 4.2 Fundamentals of data structures · 4.13 Systematic approach to problem solving · 4.1.1 Programming · 4.2.1 Data structures and abstract data types · 4.13.1 Aspects of software development

Question and mark scheme from the AQA A-Level Computer Science examination, Paper 1, June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.