Cryptography #iGCSE #ComputerScience

One of the nice and not-so-nice things about vague arrangements documents is that you have to work out how to best fill the gap.

Encryption methods are part of the Computer Security section of the course – symmetric and asymmetric encryption to be exact – and, while I could simply put two slides up on the screen and move on, I saw this as an opportunity to break away from exam style questions and have a little bit of practical fun with the students.

I introduced my Year 10 students to the Caesar cipher this week, surprised that very few of them had even heard of it. They caught on quickly though and were soon manually translating coded messages back into plaintext.

But as the lesson progressed the messages got longer and the students began to find translation very time consuming. So, after a bit of discussion, we decided it might be best to ask a computer to do the translation for us. We would still provide the ciper-text and shift key, and it would do the rest.

This allowed us (imagine that) to then recap on relevant pre-defined functions to translate characters into ASCII codes and then build an algorithm to apply the shift key to these ASCII codes. Once the codes were converted back to characters they were ready to display on the screen! Most students managed to get to this point, with some even working on alternatives (more on that later).

The next day the students returned and were given a tougher challenge: decryption without the shift key! We discussed the letter frequency graph shown above and tried to create an algorithm to accurately calculate the shift key.

The open-endedness of this task challenged everyone and the variety of solutions suggested touched on some of the actual decryption methods utilised.

A few students suggested a brute force decryption of a digest of the entire message, looking for a small number of short English words before comparing the calculated shift key to the frequency analysis graph. When challenged further they explained that this would decrease the processing time of the decryption algorithm as it wouldn’t have to translate as many characters. Some students had even had researched further to find out which were the most used English words in written text!

The students rounded off the lesson by creating a list of advantages and disadvantages of symmetric encryption. While students took longer on the concepts it gave them the opportunity to understand some of the ideas and issues with this type of encryption.

Next week we tackle asymmetric encryption. I can’t wait!

Social media generated art in Python #ThisIsMyClassroom #Programming #STEAM

Social media generated art in Python #ThisIsMyClassroom #Programming #STEAM

For the third blog post on this topic I wanted to use Python to generate different pieces of art without relying entirely on the random function. I decided to use the tweepy library, mainly because I had already used it to post content to Twitter but had never investigated how it could be used to read information back from Twitter.

It didn’t take long to find out how to read the latest 10 tweets from my own timeline using Python. Then I split the individual words into a list and sorted them into alphabetical order (for no real reason at the moment, but frequency analysis will follow!). Then I used the write method from the Turtle graphics library to place each word at a random location on the screen. This was my first attempt:

Screen Shot 2016-04-03 at 23.50.08

A bit tricky to read the words I thought. And I’d accidentally forgotten to penup before moving the turtle. However this accidental vector spider web became part of the artwork (because when I removed it, it looked quite boring).

A little while later I was able to change the font size at random (I changed the font to palatino after experimenting with a few others) and changing the pencolor in the same way as previous Python art programs changed the text colour too.

Screen Shot 2016-04-03 at 23.53.35

I had a lot of text to display, even just from 10 tweets, so I thought of ways to reduce the amount. I wrote a little Python subroutine that removed hashtags, mentions and URLs (as well as any other non ASCII text) and that was enough!

The video below shows the program in action. I decided to make a video this time because you can make out the individual words much more clearly at the beginning of the drawing than at the end!

As before the code is now on github (with my tweepy details removed for security). I’ve left in a commented out section of code that allows you to run a search for a keyword, hashtag or phrase instead of taking the latest timeline so you can experiment.

Any comments or improvements would be much appreciated!