Welcome back to another edition of {Kids: Code}, the free weekly newsletter to help you on your coding journey! This week is a bit of a short one, but that doesn’t mean the it isn’t still important, does it? We’re gonna go over what “encryption” means first before telling you about Code.org’s “App Lab” and a few great and fun games to teach you more about the wonders of CSS.
Want to reach out to us? You can contact us here or check us out on Twitter!
Have you ever watched the news and seen the word encryption thrown around? It's a big topic of discussion these days - and may sound scary at first! However, understanding encryption is easier than you might think. We thought we'd take the next two issues and go over how to build your own basic encryption and decryption code! This way, you can better understand the technology debates happening around you (and maybe pass some coded messages to friends).
What is Encryption?
Encryption is the act of taking some data (such as a message) and encoding it with another piece of data (a cipher, or a key). The extra data means that whoever is receiving the message would need the cipher in order to read it! Encryption algorithms have a long and storied history, but for the sake of an example, we'll build a very basic one ourselves. Ours will do what's called a substitution cipher - swapping letters around so our message isn't readable unless you know what to swap back (using the key).
Encrypting
Let's first build our key for what letters should be swapped. In Python, we can use a Dictionary
for this task (in other languages, you'd most likely use a Map
or Object
):
KEY = {
"A": "Z",
"B": "C" }
In our Dictionary above, we've set A
to be swapped with Z
and B
to be swapped with C
. Now let's take a look at encrypting a message!
KEY = {
"A": "Z",
"B": "C"
}
text = "BANANA"
encrypted_text = ""
for letter in text:
uppercase = letter.upper()
if uppercase in KEY:
encrypted_text += KEY[uppercase]
else:
encrypted_text += uppercase
print(encrypted_text)
In this code, we step through our word (BANANA
) and check to see if our key has a replacement to use. If it does, we add that letter into our encrypted_text
. If not, we just use the existing letter.
A fun exercise
Get creative! You can build out theKEY
to have more letters. Make your own cipher and have fun!
If we run our code, we'll see the encrypted form of BANANA
is CZNZNZ
. Curious how we decrypt it? Come back next week and we'll go over the decryption side!
Code.org has put together something called the App Lab - a place where you get to use your Python know-how to build apps! The great thing is that you can choose whether to use block coding or text coding, and even take some sample apps they have and try to “remix” them to make them even better. App Lab works in all modern browsers and is a great way to flex your Python skills at home or in the classroom. [Recommended ages 13+]
Learn CSS by playing games!
Twitter user @heyOnuoha has put together a great list of games that teach you to code in CSS by playing them! Sometimes the best way to learn something is to make your brain think that you’re not actually learning it - you’re just having fun. You can click the link above to see the thread, or check out the Tweets directly below!
This Week’s Vocabulary Word
Encryption
The act of encoding some data (a message, image, or anything else) with a key or cipher.