## Encryption

This guide has been designed to guide you through a simple encryption programme using the caesar cypher.

The caesar cypher is a simple but effective system used by julius caesar. This website has an excellent description of the Caesar Cypher as does this one.

We will use all 26 letters of the alphabet but both uppercase and lowercase so our cypher will use MOD 52.
MOD means take the remainder so 30 mod 52 is 30 but 60 mod 52 is 8, the remainder after dividing by 52.
MOD is short for "Modular arithmetic".

# Stage 1 - The plain text

Start a new Scratch project - "File" and then "New"

There are some terms that you need to know.

• The text that is being encrypted is called "plain text".
• The encrypted version of the plain text is called "cypher text"
• The number of places left or right that the alphabet moves is called the "offset". The person who receives the cypher text must uise the same offset to decrypt it. In effect the offset is the key.

The next step is to get Scratch to ask for a phrase from the user.use the ask block from "sensing" to do this. Change the default text "What is your name?" to be "What is the plain text?". Scratch will store whatever the user types in as a system variable called "answer".

The next step used a counting variable. You will use this technique quite frequently.

The problem is we are to repeat a process once for every letter in the phrase that the user wants to encrypt. So would could use the repeat block, but this needs to know how many times we are to repeat the task and we don't know how many, so we use a variable.

Traditionally the letter i is used. If another variable is required to do a similar job them we would use the letter j and then k if necessary.

So make a variable called i and write the code to set the value of i to be 1.

We are going to repeat the next process once for every letter in the phrase that the user enters. There is a block to tell us the number of characters (or length) in a phrase (or string) that Scratch has stored in the system variable called "answer". There is a block called "length of", drag this in and then drag the variable "answer" to replace the word "World".

Add a repeat block to the code and drop the length of on to the number of times the loop is to be repeated.

Now we need to inspect the phrase (or string which is the proper name for a set of text) so we use "letter of". Drag the "letter of" block and drag the system variable "answer" to replace "World". Then drag the variable i from the variables to replace the number 1 so that instead of "letter 1 of world" the block says "letter i of answer". The variable i starts at 1 and finishes when it has gone through every letter of the phrase (or string).

Make a new list called "plain_text" to store each letter of the phrase currently stored in the system variable answer, one letter at a time.

Next drag the "add thing to plain_text" block and drop "letter i of answer" over "thing".

Finally increase i by 1 by using the change i by 1 block.

Save and run the code so far. Scratch should ask you for a phrase so type in something simple such as "plain" and press the enter key. You will see your phrase (or string) appear as a set of letters in the list "plain_text".

Run the code again and what do you notice?

Each new phrase is added to plain_text rather than replace it. We solve this in the next section.

# Stage 2 - Initialisation

Frequently when progrrammers write code they find that the effect of the code that they wrote earlier still exists in the computer. When you input a string (phrase or set of letters) in to a list (or array as some programmers call it) you have to empty the list if you want to use it again.

So, drag the "delete 1 of plain_text" to the start of the thread and change 1 to be all. This will now delete the contents of the nlist "plain_text" when the thread starts so that it is empty when the user is asked for a string (phrase or sel of letters).

# Stage 3 - The Aliens

Add another sprite and give it the alien costume. The aliens have a strange but predictable motion, they will march to the right and when the first one gets to the edge of the screen they all come down a little and then march to the left and when the first one gets to the left edge of the screen, march down a bit and then march to the right and then repeat till they get to the bottom of the screen. To make life more interesting there are groups of them.

The thread that you write must check that the right most alien is near the edge of the screen and then make all of the aliens simultaneously march down a short space and then march to the left. This is done with a broadcast instruction.

Now duplicate the alien and change the "go to" block x values to be -200, -150, -100. -50, 0 and 50 for the 6 aliens.

When you press the space bar they should all move together.

When you shoot an alien with the laser the alien vanishes (or hides).

# Stage 4 - More Aliens

Add another row of aliens by duplicating each of the existing aliens and change the y value from 120 to 80

Now add two threads to each alien, one to detect being struck by a missile and then hide or vanish and then another to collide with the ship and say "Game over".

Check to see that this works correctly

# Stage 5 - Adding the barriers

Create a row of 4 barriers to protect the ship using the "barrier" costume from the "Invaders" folder. If the aliens hit the barriers the game is over and the ship cannot fire through the barriers at the aliens.

You can duplicate the barrier and change the x value of the "go to" block.to be -150, -50, 50 and 150. This will space the barriers out neatly.

# Stage 2 - The Laser

Add the largest asteroid from the folder and give it the motion as shown in hte image. The idea of the game is that when the asteroid passes out of view it will continue its journey in the same direction from the opposite side of the screen

Add the other smaller asteroids as costumes to the larger asteroid.

# Stage 4 - Extension

This is the working game although there are a few little issues to clear up. First, when the missile hits an asteroid it continues still hitting the asteroid so one shot is usually enough. Change this so that the asteroids has to be hit by different missiles to be destroyed. Second, in the real game when the asteroid is struck it splits in to two so there will be two middle sizes asteroids and then each if these will divide into two. Thirdly the asteroids get faster as they get smaller.

# Year 8 Extension

The arcade game also had an interesting way of moving the spaceship. As there is no gravity it behaves like a free body, i.e. if there is no acceleration then it continues in the same direction at the same velocity. It has the same limitation as an asteroid in that if it goes off the screen then it reappears on the opposite side.

## Recent Posts

May 24

### Repairing a hyperspace window

You may have noticed the time shift in the Blue coridor, there is a redshift at certain times of the day; this has caused the bells to malfunction and the PCs are runing slow as the server room is also moving ever so slowly into the 5th dimension. The Lightspeed engineers are working hard to fix the hyperspace window being generated by the tidal effects of big data and the weaknesses in the walls caused by excessive data mining. Cambridge Analytica's data scraping has also contributred to the weakness in the space time continuum. There is no need to be afraid as everything is should be resolved in the near future; nevertheless steps are being taken, mostly from the gold staircase.

Any further information will be included here when and if we get it.

July 18

### Adventuring with A GDPR SUrveyor

The GDPR surveyors will be in the College in the near future checking that you understand your obligations under GDPR. Are you aware of the consequences? Do you know who knows about you? Do you know what the people you don't know about, know about you? Have you checked your own settings? Are you privacy minded? The GDPR surveyors will check. They know you, possibly better than you do but maybe not as well as the Internet knows you.

July 14