Skip to content

Commit

Permalink
Updates after QA
Browse files Browse the repository at this point in the history
  • Loading branch information
pjbRPF committed Dec 24, 2024
1 parent 8884d04 commit 94935fd
Show file tree
Hide file tree
Showing 10 changed files with 549 additions and 508 deletions.
10 changes: 4 additions & 6 deletions en/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ last_tested: 2017-01-01
steps:
- title: What you will make
- title: The Caesar cipher
- title: Use a Caesar cipher
challenge: true
completion:
- engaged
- title: Encrypting letters
completion:
- internal
- engaged
- title: Variable keys
- title: Encrypting entire messages
completion:
- internal
- title: Extra characters
completion:
- external
- title: Encrypting and decrypting messages
- title: Challenge
challenge: true
- title: What can you do now?
10 changes: 7 additions & 3 deletions en/step_1.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## What you will make

In this project, you'll learn how to make your own encryption program, to send and receive secret messages with a friend.
Create your own encryption program, to send and receive secret messages with a friend.

<iframe src="https://editor.raspberrypi.org/en/embed/viewer/secret-messages-complete" width="600" height="400" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen> </iframe>
### Try it!

Press **Run** and enter a key (number) when prompted.

If you need to print this project, please use the [Printer friendly version](https://projects.raspberrypi.org/en/projects/secret-messages/print).
Then enter a message to encrypt with your chosen key.

<iframe src="https://editor.raspberrypi.org/en/embed/viewer/secret-messages-complete" width="600" height="400" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen> </iframe>
18 changes: 17 additions & 1 deletion en/step_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@ To make a secret encrypted letter from a normal one, you need to have a secret k

You could use the number 3 as the key (but you can use any number you like).

To __encrypt__ the letter 'a', you just move 3 letters clockwise, which will give you the letter 'd':
--- task ---

Choose your key.

--- /task ---

If you have chosen '3' as your key, you can __encrypt__ the letter 'a' by moving 3 letters clockwise, which will give you the letter 'd':

--- task ---

Encrypt the letter 'a' with your key.

![screenshot](images/messages-wheel-eg.png)

--- /task ---

--- task ---

Use what you've learnt to encrypt an entire word.

For example, 'hello' encrypted is 'khoor'.
Expand All @@ -36,6 +50,8 @@ For example, 'hello' encrypted is 'khoor'.
+ l + 3 = __o__
+ o + 3 = __r__

--- /task ---

Getting text back to normal is called __decryption__. To decrypt a word, just subtract the key instead of adding it:

+ k - 3 = __h__
Expand Down
301 changes: 298 additions & 3 deletions en/step_3.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,300 @@
## Use a Caesar cipher
## Encrypting letters

Can you send a secret word to a friend? You'll both need to agree on a secret key before you start.
Write a Python program to encrypt a single character.

You could even send entire sentences to each other!
--- task ---

Open the [Secret Messages starter project](https://editor.raspberrypi.org/en/projects/secret-messages-starter){:target="_blank"}.

--- /task ---

--- task ---

Instead of drawing the alphabet in a circle, write it out as an `alphabet` variable.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 1
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
--- /code ---

--- /task ---

Each letter of the alphabet has a position, starting at position 0. So the letter 'a' is at position 0 of the alphabet, and 'c' is at position 2.

--- task ---

Output a letter from your `alphabet` variable by printing the letter at the position in square brackets.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 2-4
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
print(alphabet[0])
print(alphabet[6])
print(alphabet[19])
--- /code ---

--- /task ---

--- task ---

**Test:** Click the **Run** button.

You can delete the `print` statements once you've tried this out.

--- /task ---

--- task ---

Store the secret `key` in a variable.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 2
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3
--- /code ---

--- /task ---

--- task ---

Ask the user for a single letter (called a `character`) to encrypt.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 4
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

character = input('Please enter a character: ')
--- /code ---

--- /task ---

--- task ---

Find the `position` of the `character`.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 6
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

character = input('Please enter a character: ')

position = alphabet.find(character)
--- /code ---

--- /task ---

--- task ---

You can test the stored `position` by printing it. For example, that character 'e' is at position 4 in the alphabet.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 7
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

character = input('Please enter a character: ')

position = alphabet.find(character)
print(position)
--- /code ---

--- /task ---

--- task ---

**Test:** Click the **Run** button.

You should see the position in the alphabet of the character you entered.

--- /task ---

--- task ---

To encrypt the `character`, you should add the `key` to the `position`. This is then stored in a variable called `new_position`.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 9-10
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

character = input('Please enter a character: ')

position = alphabet.find(character)
print(position)

new_position = position + key
print(new_position)
--- /code ---

--- /task ---

--- task ---

**Test:** Click the **Run** button.

As your `key` is 3, it should add 3 to the `position` and store it in your `new_position` variable.

For example, letter 'e' is at position 4. To encrypt, you add the `key` (3), giving 7.

```
Please enter a character: e
4
7
```

--- /task ---

--- task ---

What happens when you try and encrypt the letter 'y'?

```
Please enter a character: y
24
27
```

Notice how the `new_position` is 27, and there aren't 27 letters in the alphabet!

--- /task ---

--- task ---

Use a `%` to tell the new position to go back to position 0 once it gets to position 26.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 9
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

character = input('Please enter a character: ')

position = alphabet.find(character)
print(position)

new_position = (position + key) % 26
print(new_position)
--- /code ---

--- /task ---

--- task ---

Finally, print the letter at the new position.

For example, adding the key to the letter 'e' gives 7, and the letter at position 7 of the alphabet is 'h'.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 12-13
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

character = input('Please enter a character: ')

position = alphabet.find(character)
print(position)

new_position = (position + key) % 26
print(new_position)

new_character = alphabet[new_position]
print(new_character)
--- /code ---

--- /task ---

--- task ---

**Test:** Click the **Run** button.

Try out your code.

--- /task ---

--- task ---

Remove some of your print statements, just printing the new character at the end.

--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 11
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

character = input('Please enter a character: ')

position = alphabet.find(character)

new_position = (position + key) % 26

new_character = alphabet[new_position]
print('The new character is: ', new_character)
--- /code ---
--- /task ---

--- task ---

**Test:** Click the **Run** button and try out your program!

--- /task ---
Loading

0 comments on commit 94935fd

Please sign in to comment.