To shift the letters in a message, you need a way to add the shift value to each letter. Computers store characters (letters, digits, symbols, etc.) as numbers called Unicode. So, you can change the characters of a message into Unicode, add (to make the shift), and then change the Unicode back into letters.
This table shows the Unicode for some familiar characters:
The unicode of
block reports the Unicode number that is used for a particular character:
The unicode as letter
block reports the character that a given Unicode number represents:
You can right-click (or control-click on a Mac) either block and select "help..." from the drop-down menu to see more details of how the block works.
unicode of
and unicode as letter
blocks. Write down the Unicode numbers for one word, give them to another student, and translate someone else's Unicode back into a word.
If you type more than one character into the input slot of unicode of
, it will report a list of the Unicode numbers of those letters:
You can shift all the letters at once by using that list as the input to the block:
The unicode as letter
block can also accept a list as input. It will report a list of the characters for those Unicode numbers:
Finally, the join
block can accept a list as input too. It will join all the letters from a list into a single string of text:
I like this idea, and we had taught it in CSP, but I believe Brian advocated for removing it entirely, which it appears we did. We should discuss why before deciding whether to add it to middle school. --MF, 10/12/21
Click for a hint about encoding a message.
unicode of
.unicode as letter
to translate the shifted Unicode back into characters.join
to join the characters into text.Why are there characters like = ? @ # ^ * { or ~ ?
Look back at the Unicode chart. Shifting text characters can result in non-alphanumeric (not letter or digit) characters. For example,
Which character in the encoded message shown here represents a space in the original message? Look back at the Unicode chart; can you see why?
Click for a hint about decoding a message.
You can decode a message the same way as you encoded it: change it to Unicode, shift, and change back. You just have to shift in the opposite direction. For example, if the original shift added 5, you need to add -5 to get the original message back.
What if your decrypted text is missing some letters?
If you copy your encrypted message with a method other than by using copy and paste (for example, by writing it by hand or typing it into a phone), some characters may disappear from your message. This is because some of the Unicode characters after 126 are printing characters that symbolize things like "delete." These characters won't get displayed in Snap!, so you can't copy them by hand, but if you use copy and paste, Snap! knows they are there.
Click for a reminder about how to create a new block.
Click for a reminder about how make a block take an input.
message
or shift value
), and press "OK."message shifted by
block to decode a message?
You can change the input slot shape by clicking the variable name in the hat block of the block editor, clicking the right-facing triangle (▸) after the "Input name" option, selecting the input type, and clicking "OK" twice.
Click for images of how to change the shift value input type.
You can learn more about the shape of input slots and how they tell Snap! and the programmer what kind of inputs are expected in Activity 3: Hexadecimal Numerals and RGB Colors behind the link "Why do the input slots to binary of hex
and hex of binary
have different shapes?" in the yellow box near the middle of page.
Research the historical use of ciphers: