Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit 3e80b2b

Browse files
authored
Merge pull request #381 from VulpineAmethyst/accessibility/4.03
Lab 4.03: Replace visually-oriented assignment with an accessible one.
2 parents 35b485f + 28cf20c commit 3e80b2b

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 4.03 Lab - Caesar Cipher
2+
3+
The Caesar cipher is one if the simplest and most straightforward ways to obfuscate text. The way it works is that the alphabet is printed on a wheel, in order, and you step through the text letter by letter by first rotating the wheel to the original letter and then rotating right a certain number of letters. To decipher the text, you rotate the wheel to the ciphered letter and then rotate left that same number of letters. Because of the rotation of the wheel, Caesar ciphers are commonly abbreviated 'rot' and then the number of spaces to rotate, e.g. 'rot13'. An example of rot13 in action is below:
4+
5+
> Input: Hello world
6+
> Output: Uryyb jbeyq
7+
8+
The rot13 mapping looks like this:
9+
10+
> ABCDEFGHIJKLMNOPQRSTUVWXYZ
11+
> NOPQRSTUVWXYZABCDEFGHIJKLM
12+
13+
For this assignment, you will write a single function, `cipher`. This function will take a single letter and return the letter 13 steps to the right. To make it easier for you, a `letter_to_number()` function is provided which converts letters to their numerical position in the alphabet.
14+
15+
```py
16+
# Name: letter_to_number
17+
# Purpose: Convert a letter in the alphabet to its corresponding location in the alphabet.
18+
# Parameters: The letter to convert, as a string.
19+
# Returns: An integer representing the position, zero-indexed, of the letter in the alphabet, or None if it's not a letter.
20+
def letter_to_number(letter):
21+
letter = letter.lower()
22+
if letter in 'abcdefghijklmnopqrstuvwxyz':
23+
return ord(letter) - ord('a')
24+
return None
25+
26+
def cipher(letter):
27+
# function body goes here
28+
29+
text = [
30+
'Mary had a little lamb',
31+
'How much wood would a woodchuck chuck if a chuck-wood could chuck wood?',
32+
'This is the song that never ends, it goes on and on, my friends...',
33+
'I want to be the very best, like no one ever was. To catch them is my real test, to train them is my cause.'
34+
]
35+
```
36+
37+
Note that the rot13 cipher is self-deciphering—that means running the cipher function on ciphered text will return the original text. This allows you to easily verify if your function is correct.
38+
39+
## Bonus
40+
41+
Rewrite `cipher()` to take an additional, integer, argument, which specifies how many spaces to the right the function rotates the alphabet. Write a new function, `decipher()`, which has a similar function contract but rotates left rather than right. Your code is correct if `decipher(cipher('a'))` returns `'a'`.

units/4_unit/03_lesson/lesson.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Students will be able to...
1414
* [4.03 Slide Deck](https://github.com/TEALSK12/2nd-semester-introduction-to-computer-science/raw/master/units/4_unit/slidedecks/Intro%20Python%204.03%20TEALS.pptx)
1515
* [Do Now][]
1616
* [Lab - Nested For Loops][] ([docx][]) ([pdf][])
17+
* [Lab - Caesar Cipher][] ([docx][https://github.com/TEALSK12/2nd-semester-introduction-to-computer-science/raw/master/units/4_unit/03_lesson/lab_caesar.docx]) ([pdf][https://github.com/TEALSK12/2nd-semester-introduction-to-computer-science/raw/master/units/4_unit/03_lesson/lab_caesar.pdf])
1718
* Read through the Do Now, lesson, and lab so that you are familiar with the requirements and can assist students.
1819
* Video Explanation of nested `for` Loops.
1920
* [Nested Loops](https://youtu.be/fyP4SXpkYG4)
@@ -69,7 +70,8 @@ Students will be able to...
6970

7071
### 3. Lab
7172

72-
* The lab asks students to write functions that produce different outputs using nested `for` loops.
73+
* The pattern lab asks students to write functions that produce different outputs using nested `for` loops.
74+
* The Caesar cipher lab asks students to write a simple letter rotation function which enciphers letter-by-letter, necessitating nested `for` loops.
7375

7476
### 4. Debrief
7577

@@ -85,5 +87,6 @@ Students will be able to...
8587

8688
[Do Now]: do_now.md
8789
[Lab - Nested For Loops]: lab.md
90+
[Lab - Caesar Cipher]: lab_caesar.md
8891
[pdf]: https://github.com/TEALSK12/2nd-semester-introduction-to-computer-science/raw/master/units/4_unit/03_lesson/lab.pdf
8992
[docx]: https://github.com/TEALSK12/2nd-semester-introduction-to-computer-science/raw/master/units/4_unit/03_lesson/lab.docx

0 commit comments

Comments
 (0)