Module · Detail

Caesar Cipher in Python

This module introduces basic concepts of encryption and character processing in Python. It connects algorithmic thinking with the implementation of mathematical operations in a functional structure.

Time 35 minutes
Format Compact
Language Python 3
Tasks 1
Preview Image: Caesar Cipher (A–Z) in Python

Introduction (Original excerpt)

You are programming a function caesar_encrypt(text, key), which encrypts text into cipher text. Only uppercase letters A–Z are shifted by key positions cyclically (after Z it goes back to A again). All other characters (e.g., spaces, periods, commas, digits) remain unchanged.

Didactic Classification

Subjective Objective

The module introduces the fundamental functionality of simple encryption methods and connects this to central concepts in programming. At its core is the implementation of a Caesar cipher, where characters are systematically transformed. The mapping of characters to numbers using ord() and chr() is utilized and a cyclic shift is realized through modulo arithmetic. Learners structure the algorithm as a function and apply it to character strings. The connection between mathematical model (number range 0-25) and concrete implementation is explicitly established.

Competence development

Didactic added value in teaching

Flow of the lesson unit

1

Caesar encrypt: Function complete

In this step, the central function for Caesar encryption is implemented. Only uppercase letters are transformed, while all other characters remain unchanged. The task focuses on correct implementation of cyclic shift and structured processing of a text character by character.

  • Didactic focus: Connection between character processing and modulo arithmetic
  • Typical challenge: Correct implementation of cyclic shift and fall-through

Work assignment (excerpt)

1. Implement function to encrypt uppercase letters A-Z
2. Leave all other characters unchanged
3. Correctly implement cyclic shift with modulo 26
4. Verify results using test cases

Example (excerpt)

1
2
3
4
5
6
base = ord('A')
for ch in text:
    if 'A' <= ch <= 'Z':
        pos = ord(ch) - base
        new_pos = (pos + key) % 26
        result += chr(base + new_pos)

This fragment illustrates the central transformation of characters through numerical representations and modulo arithmetic.

Hints for teaching practice

This module connects algorithmic encryption with systematic character processing, creating a clear foundation for traceable implementations.

The clear structure of the task supports targeted implementation and facilitates organization and securing results in class.

Request a demo access and test the module in your own course context.