For more information, see Encryption on Wikipedia. Encryption is a technique used to transform a string into another, such that the algorithm to reverse the transformation is complex and usually only decipherable by the original encrypter or with a specific decrypter.
Simple Encryption
Substitution Cipher
The Substitution Cipher is a simple cipher technique, which involves simply replacing each character in a message with another one, either also part of the alphabet or with a symbol.
Cesarean Cipher
The Cesarean Cipher is a simple substitution encryption technique "shifts" each letter of the alphabet by a fixed amount. The following algorithm can be used to create a Cesarean Cipher.
- First, create a list of every letter in the alphabet.
- Then, using the
(item # of [] in [Alphabet v])
block, convert the string into a list of the alphabetical position of each letter of the string. A "0" would represent a space. - Then, delete the first letter of the alphabet and add that letter to the end. Repeat this step with the value of the Cesarean shift.
- Then, iterating through each item of the list, replace each number in the original list with the letter of in that position in the new alphabet list, like so:
(item (...) of [Alphabet v])
. Take care to replace a "0" with a space instead. - Finally, join these back into a string and report the result.
To decode, do the same thing, except "shift" backwards. For example, with a Cesarean shift of 3, a "d" would be an "a" in plain text.
This method can be used to convert a string like: "hello world" into "khoor zruog"
Complex Encryption
Complex encryption systems generally return a fixed length string, no matter how long the input is. These kinds of encryptions, often called hashes, are widely used to securely store passwords in a database.
Encryption in Scratch
Encryption can be used in lists in Scratch. Suppose a list contains numbers, but one wants those values to be hidden in an encrypted way. A simple method would be the following script:
set [item# v] to (1) //begin the encryption with the first value repeat (length of [values v]) //repeat for the amount of numbers that are to be encrypted replace item (item#) of [values v] with (((item (item#) of [values v]) * (2.463)) + (7.293)) //simple algorithm for encryption change [item# v] by (1) //move on to the next value in the list
Then, to decrypt the values, the algorithm must be reversed:
set [item# v] to (1) repeat (length of [values v]) replace item (item#) of [values v] with (((item (item#) of [values v]) - (7.293)) / (2.463)) change [item# v] by (1)
Complex numbers with multiple decimal places are used for greater difficulty in deciphering the code. The more mathematical functions and complex numbers are used, the safer the encryption is. Encrypting values in a Scratch project can be difficult to do safely, though, since a user can See Inside and view the encryptor itself. However, if the decipher algorithm is not visible, it may still be difficult to decipher the codes if an intricate algorithm or method was used.
Warning: | No personal information should ever be entered into a Scratch project, even if it is encrypted. |
See Also
- Encryption on Wikipedia
- Cryptography on Wikipedia
- Cloud Encryption