-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8870664
commit 0b26c8a
Showing
7 changed files
with
1,566 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"description": { | ||
"names": { | ||
"en": "Bar Plot" | ||
} | ||
}, | ||
"labels": [ | ||
"real-world programming" | ||
], | ||
"internals": { | ||
"token": "G4iAJA8szv6ihdYCfAXzZdQH_Zwp9BugYTY2t-YkRGAYBPXDcpU_UHSRE4S6WJ62", | ||
"_info": "These fields are used for internal bookkeeping in Dodona, please do not change them." | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
I've left a secret message for you in a text file [here](media/secret.txt). Because it's very | ||
secret I've encrypted it using a Caesar cipher. | ||
|
||
Your task is to write a function to decrypt Caesar ciphertext. First let's understand what a Caesar | ||
cipher does with an example: | ||
|
||
Here is some text to encrypt: `"I CAN HAZ CHEESEBURGER"`. The Caesar cipher also needs a "key" which is a number | ||
between 1 and 26. This number is used to "rotate" the plaintext input characters. For this example, | ||
the key is `1`. | ||
|
||
The first letter is `"I"`. `"I"` "rotated" by `1` is the letter after `"I"` which is `"J"`. So the | ||
encrypted ciphertext is `"J"` so far. | ||
|
||
The next letter is `" "`. Spaces are not changed by encryption and decryption so the encrypted | ||
ciphertext is now: `"J "`. | ||
|
||
The same logic applies to all lettes in the string up until `"Z"`. At this point the plaintext, | ||
`"I CAN HA"` has been encryped to `"J DBO IB"`. To encrypt a `"Z"` you count back again from the | ||
beginning of the alphabet. So the plaintext `"Z"` is encrypted to `"A"`. | ||
|
||
This is why it's called a "rotation". If you write the latin alphabet, A...Z on a circular piece of | ||
paper. Then again on a slightly smaller piece of paper. Rotate one of the circular pieces of paper by | ||
the key and this gives the mapping between plaintext letters and ciphertext letters. | ||
|
||
 | ||
|
||
The final encryption of the string `"I CAN HAZ CHEESEBURGER"` with a key of `1` is then: | ||
`"J DBO IBA DIFFTFCVSHFS"`. | ||
|
||
Your task is to write a function to decode caesar ciphers called `decrypt`. Your function should accept | ||
2 arguments: | ||
|
||
- The encrypted ciphertext (as uninterpreted binary data type: `bytes`) | ||
- The key (type: `int`) | ||
|
||
Your function should return a `str`. | ||
|
||
You can use this template: | ||
|
||
```python | ||
def decrypt(ciphertext: bytes, key: int) -> str: | ||
... | ||
``` | ||
|
||
|
||
You should also `print()` my message to the console using your `decrypt` function. | ||
You can use a key of `13` to decode my message. The message is in a file called, `"secret.txt"`. | ||
|
||
## Example | ||
|
||
```console?lang=python&prompt=>>> | ||
>>> decrypt(b'B NFTTBHF', 1) | ||
"A MESSAGE" | ||
>>> decrypt(b'', 12) | ||
"" | ||
>>> decrypt(b'QBUN CM SIOL HUGY', 6) | ||
"WHAT IS YOUR NAME" | ||
>>> decrypt(b'HELLO WORLD', 26) | ||
"HELLO WORLD" | ||
``` | ||
|
||
|
||
Do not forget to include a docstring on your `decrypt` function and a test function called | ||
`test_decrypt` that returns `"Success"` if the `decrypt` function passes all tests. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
- tab: "Bar plot global data" | ||
testcases: | ||
- expression: | ||
python: "submission.bar_plot_global('HadCRUT.5.0.1.0.analysis.summary_series.global.monthly.csv')" | ||
return: !oracle | ||
value: "" | ||
oracle: "custom_check" | ||
file: "test.py" | ||
name: "Image check" | ||
arguments: [] |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from evaluation_utils import EvaluationResult, ConvertedOracleContext | ||
from matplotlib.testing.compare import compare_images | ||
|
||
def evaluate_test(context: ConvertedOracleContext): | ||
context.actual.savefig("actual.png") | ||
result = compare_images("actual.png", "expected.png") | ||
return EvaluationResult( | ||
result=result is None, | ||
readable_expected="", | ||
readable_actual="", | ||
messages=[result] if result is not None else [], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import csv | ||
from datetime import datetime | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
def clean_global_data(raw: dict[str, str]) -> dict: | ||
return { | ||
"time": datetime.strptime(raw["Time"], "%Y-%m"), | ||
"temperature": float(raw["Anomaly (deg C)"]) | ||
} | ||
|
||
def parse_global_data(filename: str) -> list[dict]: | ||
data = [] | ||
with open(filename) as raw: | ||
reader = csv.DictReader(raw) | ||
for row in reader: | ||
data.append(clean_global_data(row)) | ||
|
||
def times(data: list[dict]) -> list[datetime]: | ||
t = [] | ||
for obs in data: | ||
t.append(obs["time"]) | ||
|
||
return t | ||
|
||
def temperatures(data: list[dict]) -> list[float]: | ||
t = [] | ||
for obs in data: | ||
t.append(obs["temperature"]) | ||
return t | ||
|
||
def bar_plot_global(filename: str): | ||
data = parse_global_data(filename) | ||
xaxis = times(data) | ||
yaxis = temperatures(data) | ||
|
||
return plt.bar(x=xaxis, height=yaxis) |
Oops, something went wrong.