-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from raspberrypilearning/draft
- Loading branch information
Showing
11 changed files
with
121 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
#!/bin/python3 | ||
|
||
alphabet = 'abcdefghijklmnopqrstuvwxyz' | ||
newMessage = '' | ||
|
||
message = input('Please enter a message: ') | ||
|
||
key = input('Enter a key (1-26): ') | ||
key = input('Please enter the key: ') | ||
key = int(key) | ||
new_message = '' | ||
|
||
for character in message: | ||
if character in alphabet: | ||
position = alphabet.find(character) | ||
newPosition = (position + key) % 26 | ||
newCharacter = alphabet[newPosition] | ||
newMessage += newCharacter | ||
else: | ||
newMessage += character | ||
message = input('Please enter a message: ') | ||
|
||
print('Your new message is: ', newMessage) | ||
for character in message: | ||
if character in alphabet: | ||
position = alphabet.find(character) | ||
new_position = (position + key) % 26 | ||
new_character = alphabet[new_position] | ||
new_message += new_character | ||
else: | ||
new_message += character | ||
print(new_message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,7 @@ | ||
## Introduction: | ||
## 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. This project ties in with the "Earth to Principia" activity on page 16 of the Space Diary. | ||
In this project, you'll learn how to make 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> | ||
|
||
### Additional information for club leaders | ||
|
||
If you need to print this project, please use the [Printer friendly version](https://projects.raspberrypi.org/en/projects/secret-messages/print). | ||
|
||
|
||
--- collapse --- | ||
--- | ||
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. | ||
|
||
## Offline Resources | ||
This project can be [completed offline](https://www.codeclubprojects.org/en-GB/resources/python-working-offline/) if preferred. | ||
|
||
You can find the completed project in the 'Volunteer Resources' section, which contains: | ||
|
||
+ messages-finished/messages.py | ||
+ messages-finished/friends.py | ||
|
||
(All of the resources above are also downloadable as project and volunteer `.zip` files.) | ||
|
||
## Learning Objectives | ||
+ Iteration (looping) over a string variable; | ||
+ The `find()` method; | ||
+ The modulus operator (`%`). | ||
|
||
## Challenges | ||
+ Use a Caesar cipher - encrypt and decrypt letters and words manually; | ||
+ Variable keys - allowing the user to input a chosen key; | ||
+ Encrypting and decrypting messages - encrypting and decrypting whole messages; | ||
+ Friendship calculator - applying text iteration to a new problem. | ||
|
||
## Frequently Asked Questions | ||
+ When searching using `find()` or `if char in alphabet:`, note that searches are case-sensitive. Children can use: | ||
|
||
```python | ||
message = input("Please enter a message to encrypt: ").lower() | ||
``` | ||
|
||
to make the input lower case before searching. | ||
|
||
--- /collapse --- | ||
|
||
|
||
--- collapse --- | ||
--- | ||
title: Project materials | ||
--- | ||
## Project resources | ||
* [.zip file containing all project resources](resources/secret-messages-project-resources.zip) | ||
* [Offline blank Python file](resources/new-new.py) | ||
|
||
## Club leader resources | ||
* [.zip file containing all completed project resources](resources/secret-messages-volunteer-resources.zip) | ||
* [secret-messages-finished/messages.py](resources/secret-messages-finished-messages.py) | ||
* [offline complete 'Friendship calculator' challenge](resources/friendship-calculator-finished-friends.py) | ||
|
||
--- /collapse --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
--- challenge --- | ||
## Challenge: Use a Caesar cipher | ||
## Use a Caesar cipher | ||
|
||
Can you send a secret word to a friend? You'll both need to agree on a secret key before you start. | ||
|
||
You could even send entire sentences to each other! | ||
|
||
|
||
--- /challenge --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
--- challenge --- | ||
## Challenge: Variable keys | ||
Modify your program, so that the user can enter their own key to use. You'll need to get the user's input, and store it in the `key` variable. | ||
## Variable keys | ||
|
||
Remember to use the `int()` function to convert the input to a whole number. | ||
Modify your program, so that the user can enter their own key to use. | ||
|
||
You can then use a negative key to decrypt messages! | ||
You'll need to get the user's input, and store it in the `key` variable. | ||
|
||
--- code --- | ||
--- | ||
language: python | ||
filename: main.py | ||
line_numbers: true | ||
line_number_start: 1 | ||
line_highlights: 2-3 | ||
--- | ||
alphabet = 'abcdefghijklmnopqrstuvwxyz' | ||
key = input('Please enter the key: ') | ||
key = int(key) | ||
|
||
character = input('Please enter a character: ') | ||
|
||
position = alphabet.find(character) | ||
|
||
new_position = (position + key) % 26 | ||
|
||
--- /challenge --- | ||
new_character = alphabet[new_position] | ||
print('The new character is: ', new_character) | ||
--- /code --- | ||
|
||
You can then use a negative key to decrypt messages! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.