Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft #53

Merged
merged 10 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion en/code/secret-messages-starter/project_config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: 'Secret Messages Starter'
identifier: 'secret-messages-starter'
type: 'python'
type: 'python'
Binary file removed en/images/messages-alphabet-array.png
Binary file not shown.
Binary file removed en/images/messages-alphabet.png
Binary file not shown.
Binary file modified en/images/messages-array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed en/images/messages-best-friends.png
Binary file not shown.
Binary file removed en/images/messages-character-finished.png
Binary file not shown.
Binary file removed en/images/messages-character.png
Binary file not shown.
Binary file removed en/images/messages-else-test.png
Binary file not shown.
Binary file removed en/images/messages-else.png
Binary file not shown.
Binary file removed en/images/messages-enc-test.png
Binary file not shown.
Binary file removed en/images/messages-extra-characters.png
Binary file not shown.
Binary file removed en/images/messages-finished.png
Binary file not shown.
Binary file removed en/images/messages-friends-code.png
Binary file not shown.
Binary file removed en/images/messages-friends.png
Binary file not shown.
Binary file removed en/images/messages-if-test.png
Binary file not shown.
Binary file removed en/images/messages-if.png
Binary file not shown.
Binary file removed en/images/messages-key.png
Binary file not shown.
Binary file removed en/images/messages-loop-test.png
Binary file not shown.
Binary file removed en/images/messages-loop.png
Binary file not shown.
Binary file removed en/images/messages-message.png
Binary file not shown.
Binary file removed en/images/messages-modulus-bug.png
Binary file not shown.
Binary file removed en/images/messages-modulus.png
Binary file not shown.
Binary file removed en/images/messages-newcharacter.png
Binary file not shown.
Binary file removed en/images/messages-newmessage.png
Binary file not shown.
Binary file removed en/images/messages-newposition-print.png
Binary file not shown.
Binary file removed en/images/messages-newposition-test.png
Binary file not shown.
Binary file removed en/images/messages-newposition.png
Diff not rendered.
Binary file removed en/images/messages-position-test.png
Diff not rendered.
Binary file removed en/images/messages-position.png
Diff not rendered.
Binary file removed en/images/messages-print-message-characters.png
Diff not rendered.
Binary file removed en/images/messages-print-message-comment.png
Diff not rendered.
Binary file removed en/images/messges-message-add-character.png
Diff not rendered.
1 change: 0 additions & 1 deletion en/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ steps:
completion:
- internal
- title: 'Challenge: Encrypting and decrypting messages'
- title: 'Challenge: Friendship calculator'
25 changes: 1 addition & 24 deletions en/step_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

In this project, you'll learn how to make your own encryption program, to send and receive secret messages with a friend. This project ties in with the "Earth to Principia" activity on page 16 of the Space Diary.

<div class="trinket">
<iframe src="https://trinket.io/embed/python/402256078c?outputOnly=true&start=result" width="600" height="500" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen>
</iframe>
<img src="images/messages-finished.png">
</div>
<iframe src="https://editor.raspberrypi.org/en/embed/viewer/secret-messages-complete" width="600" height="400" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen> </iframe>

### Additional information for club leaders

Expand All @@ -22,18 +18,6 @@ title: Club leader notes
## Introduction:
In this project, children will learn how to make an encryption program, to send and receive secret messages with a friend. This project introduces iteration (looping) over a text string.

## Online Resources

__This project uses Python 3.__ We recommend using [trinket](https://trinket.io/) to write Python online. This project contains the following Trinkets:

+ [New (blank) Python Trinket -- jumpto.cc/python-new](http://jumpto.cc/python-new)

There is also a trinket containing the finished project:

+ [‘Secret Messages’ Finished -- trinket.io/python/402256078c](https://trinket.io/python/402256078c)

+ [‘Friendship Calculator’ Finished -- trinket.io/python/2e852cd687](https://trinket.io/python/2e852cd687)

## Offline Resources
This project can be [completed offline](https://www.codeclubprojects.org/en-GB/resources/python-working-offline/) if preferred.

Expand All @@ -49,10 +33,6 @@ You can find the completed project in the 'Volunteer Resources' section, which c
+ The `find()` method;
+ The modulus operator (`%`).

This project covers elements from the following strands of the [Raspberry Pi Digital Making Curriculum](https://rpf.io/curriculum):

+ [Combine programming constructs to solve a problem.](https://www.raspberrypi.org/curriculum/programming/builder)

## Challenges
+ Use a Caesar cipher - encrypt and decrypt letters and words manually;
+ Variable keys - allowing the user to input a chosen key;
Expand All @@ -77,14 +57,11 @@ title: Project materials
---
## Project resources
* [.zip file containing all project resources](resources/secret-messages-project-resources.zip)
* [Online blank Python Trinket](http://jumpto.cc/python-new)
* [Offline blank Python file](resources/new-new.py)

## Club leader resources
* [.zip file containing all completed project resources](resources/secret-messages-volunteer-resources.zip)
* [Online completed Trinket project](https://trinket.io/python/402256078c)
* [secret-messages-finished/messages.py](resources/secret-messages-finished-messages.py)
* [Online completed 'Friendship calculator' challenge](https://trinket.io/python/2e852cd687)
* [offline complete 'Friendship calculator' challenge](resources/friendship-calculator-finished-friends.py)

--- /collapse ---
268 changes: 235 additions & 33 deletions en/step_4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,272 @@

Let's write a Python program to encrypt a single character.

--- task ---

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

+ Open the blank Python template Trinket: <a href="http://jumpto.cc/python-new" target="_blank">jumpto.cc/python-new</a>.
--- /task ---

+ Instead of drawing the alphabet in a circle, let's write it out as an `alphabet` variable.
--- task ---

![screenshot](images/messages-alphabet.png)
Instead of drawing the alphabet in a circle, let's write it out as an `alphabet` variable.

+ 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.
--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 1
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
--- /code ---

![screenshot](images/messages-array.png)
--- /task ---

+ You can get a letter from your `alphabet` variable by writing the position in square brackets.
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.

![screenshot](images/messages-alphabet-array.png)
--- task ---

You can delete the `print` statements once you've tried this out.
You can get a letter from your `alphabet` variable by writing the position in square brackets.

+ Next, you'll need to store the secret `key` in a variable.
--- 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 ---

![screenshot](images/messages-key.png)
You can delete the `print` statements once you've tried this out.

+ Next, ask the user for a single letter (called a `character`) to encrypt.
--- /task ---

![screenshot](images/messages-character.png)
--- task ---

+ Find the `position` of the `character`.
Next, you'll need to store the secret `key` in a variable.

![screenshot](images/messages-position.png)
--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 2
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3
--- /code ---

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

![screenshot](images/messages-position-test.png)
--- task ---

+ To encrypt the `character`, you should add the `key` to the `position`. This is then stored in a `newPosition` variable.
Next, ask the user for a single letter (called a `character`) to encrypt.

![screenshot](images/messages-newposition.png)
--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 4
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

+ Add code to print the new character position.
character = input('Please enter a character: ')
--- /code ---

![screenshot](images/messages-newposition-print.png)
--- /task ---

+ Test out your new code. As your `key` is 3, it should add 3 to the `position` and store it in your `newPosition` variable.
--- task ---

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

![screenshot](images/messages-newposition-test.png)
--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 6
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

+ What happens when you try and encrypt the letter 'y'?
character = input('Please enter a character: ')

![screenshot](images/messages-modulus-bug.png)
position = alphabet.find(character)
--- /code ---

Notice how the `newPosition` is 27, and there aren't 27 letters in the alphabet!
--- /task ---

+ You can use a `%` to tell the new position to go back to position 0 once it gets to position 26.
--- task ---

![screenshot](images/messages-modulus.png)
You can test the stored `position` by printing it. For example, that character 'e' is at position 4 in the alphabet.

+ Finally, you want to print the letter at the new position.
--- code ---
---
language: python
filename: main.py
line_numbers: true
line_number_start: 1
line_highlights: 7
---
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 3

For example, adding the key to the letter 'e' gives 7, and the letter at position 7 of the alphabet is 'h'.
character = input('Please enter a character: ')

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

--- /task ---

--- task ---

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

--- 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 ---

+est out your new code. 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 ---

You can 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, you want to 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 ---

Try out your code. You can also 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 ---

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

+ Try out your code. You can also remove some of your print statements, just printing the new character at the end.

![screenshot](images/messages-enc-test.png)
Loading
Loading