How the Scrambled Alphabet Cipher Works
The scrambled alphabet cipher has two arguments, text and encrypt. In this case, the cipher accepts upper-case characters or words. The encrypt argument accepts True or False. True encrypts, and False decrypts. Inside the function, there is an alphabet, and a cryptabet. The cryptabet is a scrambled version of the alphabet. It also has an empty result string that will be used to build the encryption result.
This step is only performed if the function is called with the encrypt argument set to False. When the function encrypts, it uses alpha and crypta as declared above. When it decrypts, alpha has to store “PTQGMKCRSVEXADZBJFOWYNIHLU” and crypta has to store “ABCDEFGHIJKLMNOPQRSTUVWXYZ”. So if encrypt is False, the statements below and indented shuffle the two strings. It does so by copying the alpha string into temp, then copying the crypta into alpha. Lastly, temp — which contains the original alpha — gets copied to crypta.
The encryption loop starts by making sure the letter is upper case with set letter to (upper(letter)). Then, it finds the index of the letter in alpha with set index to ((alpha) find index of (letter)). Finally, it looks up the letter with that index in the cryptabet and appends the string result with set result to (join (result)(char from (crypta) at (index)).
The project starts executing statements here, with the usual pause (1000) and a message to set your keyboard to CAPS LOCK.
Inside the main loop, an input statement prompts you to type a CAPS LOCK word and stores the result in a variable named text. Then, set result to (call scramble(text, True)) encrypts the text you typed and stores it in a variable named result, which gets printed.
Next, set result to (call scramble(result, False)) decrypts the string, and the last serial write line statement displays the original text you entered.