Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help making a cloud variable encoder and decoder
- Rockdog66
-
23 posts
Help making a cloud variable encoder and decoder
Hi is there anyprojects that could help me with encoding/decoding text into a cloud variable. I have tryed but I fail much. So if anyone could help that would be great!
- lederniersamourai
-
500+ posts
Help making a cloud variable encoder and decoder
A very simple solution id to do this:
Now you encode easily ONE CHARACTER as follows:
Then you get the code of c. The 1000 + idx is used for padding and allows you to have a key string of more than 100 characters. If you want to encode all characters, you might need a key string of 128 charactes. I did not put all characters in key.
Then you can encode a fill string by joining the encoding of each char:
Now decoding is very easy:
The long expression is:
set to (join (decode of s) (letter ((0) + (join (letter (idxd + 1) of (s)) (join (letter (idxd + 2) of (s)) (letter (idxd + 3) of (s))))) of (key)))
Then you get the decoding into “decode of s”
Of course you can optimize this code and invent more complex encode/decode.
This one is simple and clear.
when green flag clickedThe last one is space and underscore.
set [key v] to [abcdefghijklmnopqrstuvwxyz]
set [key v] to (join (key) [ABCDEFGHIJKLMNOPQRSTUVWXYZ])
set [key v] to (join (key) [0123456789])
set [key v] to (join (key) [+=)(/&%*:;,.><éà{}])
set [key v] to (join (key) [ _])
Now you encode easily ONE CHARACTER as follows:
define encodeChar [c]
set [idxc v] to (1)
repeat until <(c) = (letter (idxc) of (key))>
change [idxc v] by (1)
end
set [code of c v] to ((1000) + (idxc))
Then you get the code of c. The 1000 + idx is used for padding and allows you to have a key string of more than 100 characters. If you want to encode all characters, you might need a key string of 128 charactes. I did not put all characters in key.
Then you can encode a fill string by joining the encoding of each char:
define encodeString [s]
set [idxs v] to (1)
set [code of s v] to []
repeat until <(idxs) > (length of (s))>
encodeChar (letter (idxs) of (s))
set [code of s v] to (join (code of s) (code of c))
change [idxs v] by (1)
end
Now decoding is very easy:
define decodeString [s]
set [idxd v] to (1)
set [decode of s v] to []
repeat until <(idxd) > (length of (s))>
set [decode of s v] to (join (decode of s) (letter ((0) + (join (letter (idxd + 1) of (s)) (join (letter (idxd + 2) of (s)) (letter (idxd + 3) of (s))))) of (key)))
change [idxd v] by (4)
end
The long expression is:
set to (join (decode of s) (letter ((0) + (join (letter (idxd + 1) of (s)) (join (letter (idxd + 2) of (s)) (letter (idxd + 3) of (s))))) of (key)))
Then you get the decoding into “decode of s”
Of course you can optimize this code and invent more complex encode/decode.
This one is simple and clear.
- Rockdog66
-
23 posts
Help making a cloud variable encoder and decoder
I'm bad. How would I use this
example
example
if <key [ space] pressed?> then
ask [Word] and wait
Then is there something I do here or?
end
- deck26
-
1000+ posts
Help making a cloud variable encoder and decoder
http://wiki.scratch.mit.edu/wiki/Global_High_Scores shows the method
- Discussion Forums
- » Help with Scripts
-
» Help making a cloud variable encoder and decoder