--- tags: Labs-F20, 2020 title: Lab 01 --- # Lab 1: Message Decryptor ## Problem 0 - Cakecutters Welcome to CSCI 0111 Lab! We're *so* excited to work with you. Now that you're with your partner(s), discuss one/some/all of these questions to metaphorically ["cut the cake"](https://en.wikipedia.org/wiki/Icebreaker_(facilitation)): * If you could only eat one dessert for the rest of your life, what would it be? Is that your favorite dessert? Why? * What's a dessert that you've tried to like, but just can't? * If you could go to dinner *anywhere* tonight, where would you go? How about for dessert? ***NOTE:*** If you aren't a dessert person, that's okay! Feel free to talk about food in general instead. ## Problem 1 - Cracking Encryptors You are on a top-secret case and need to send encrypted messages to your favorite [pâtissier](https://en.wikipedia.org/wiki/Pastry_chef). However, the instructions to your encryption machine are irreparably covered in chocolate, and it’s up to you to figure out how it works! The encryptor machine has 10 black-box functions that encrypt a String. Your first task is to test various inputs and figure out how each function changes the input based on the output. Once you have an idea of what an encryption function does, write a version of the function that encrypts a String in the same manner and run it through the checks in the support file. If all checks pass, then you’ve successfully built an encryptor for covert communications! ### Instructions Include this at the top of your program: ```import shared-gdrive("lab1-support-2020.arr", "1VXe5sXQzCKHFFQght67USg0ORVul_186") as support``` Now you will be able to access all of the encryptors and their testers in your Pyret file. The *encryptor functions* are named ``` support.encryptor1, support.encryptor2, support.encryptor3, support.encryptor4, ... support.encryptor10 ``` The encryptor functions take in Strings as input (e.g: ```support.encryptor1("mystery")```) and produce an encrypted result. :::info Please keep a record of what Strings you use to test each encryptor – you should be prepared to explain your choice of Strings to a TA. They will be useful for you to reference, too! ::: The *tester functions* are named, inspiringly: ``` support.test-encryptor1, support.test-encryptor2, support.test-encryptor3, support.test-encryptor4, ... support.test-encryptor10 ``` To use them, you must use the name of *your* function as an input. For example, after giving some inputs to `support.encryptor1`, you may think it always returns the String `"cs0111"` (*HINT: it doesn't do this -- just an example*). Then you would write the function: ``` fun my-cool-encryptor(str :: String) -> String: "cs0111" end ``` You would test whether your function is correct (meaning it does the same thing as `encryptor1` for all inputs) by running: ``` support.test-encryptor1(my-cool-encryptor) ``` **Hint:** The encryptors are composed of functions from the [Pyret Strings library](https://www.pyret.org/docs/latest/strings.html). Start by reading through it. **Hint:** When choosing Strings to use as inputs to the encryptors, it will be useful to vary your inputs -- think about why this could be. In what ways can you vary your Strings? ___ ### CHECKPOINT: **1. Call over a TA after you have finished encryptors 1-4 2. Call over a TA after you have finished encryptors 5-9. 3. BONUS: Can you crack `encryptor10`?** ___ ## Problem 2 - New Encryptor Swap Oh no – you just received word that a rival pâtissier broke your encryption scheme. It's up to you to create new encryption functions for your machine. ### Instructions In a new document, write an encryptor function. Call it ```new-encryptor```. It must take in a single String and produce some output. You may use any combination of functions from the [Pyret Strings library](https://www.pyret.org/docs/latest/strings.html) to build your function. Once you're done, press the "Publish" button in the Pyret Code Editor and trade links (the second link that you are given after you publish, it should include `import as`) with another group and try to crack each other's encryptors. Use the same format that you used to import ```support.arr``` -- call over a TA if you get stuck. :::info **If you're having trouble with ```import```** * Make sure that you have ```provide *``` and ``` provide-types *``` at the top of your file before you share code with the other team * Be sure to save your files ::: Write a function called `new-decryptor` that takes in the output of the other group's `new-encryptor` and decrypts it. When you think your decryptor works, consult with the other group. ___ ### CHECKPOINT: **Call over a TA once *both groups* have solved each other's encryptors.** ___ ## Problem 3 - Encrypting Numbers After building such a great encryptor, you realize that you forgot something! Your encryptor deals with Strings, but it doesn't disguise or change sequences of Numbers. This could be important if you ever want to be covert and secure. Similarly to Problem 2, write another encryptor function called `new-number-encryptor`. This function should take in a Number and produce some output. You may use any combination of functions from the [Pyret Numbers library](https://www.pyret.org/docs/latest/numbers.html). Just like with `new-encryptor`, press the “Publish” button in the Pyret Code Editor and trade links with another group to try to crack each other’s encryptors. Use the same format that you used to import `support.arr` -- call over a TA if you get stuck. Write a function called `new-number-decryptor` that takes in the output of the other group’s `new-number-encryptor` and decrypts it. When you think your decryptor works, consult with the other group. ___ ### CHECKPOINT: **Call over a TA once *both groups* have solved each other's Number encryptors.** ___ ## Success! Nice! Your new encryptor functions worked! You can send secure messages to your pâtissier without worrying about anybody listening in.