My son is interested in the ROT-13 cypher. I would like to help him write a program in MIT Scratch that can take a string as input and return the ROT-13 encoded text as output. To do this, the program will need to take the string, separate out all the characters, change the characters according to the ROT-13 cypher, and reassemble them back into the string.
I recognize that Scratch isn't really built for string manipulation, but its the programming environment that my son understands. Is this kind of string manipulation feasible in Scratch? If so, how would it be done? To get started, how would you split up a string into the equivalent of an array of characters?
The best way to do this is by simple iteration.
set [i v] to (0)
repeat (length of (originalString))
change [i v] by (1)
add (letter (i) of (originalString)) to [characters v]
end
(Visual representation)
The list characters
will contain each character of the original string.
You can do it without variables too (using the length of the current output)...
delete (all v) of [Output v]
repeat (length of (originalString))
add (letter((length of [Output v]) + (1)) of (originalString)) to [Output v]
end
Visual Representation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With