Discuss Scratch

youormeletsbringit
Scratcher
82 posts

Most compact Encoder & Decoder!

A lot of encoders & decoders out there have a lot of separate blocks. I've managed to compact it as small as I possibly could. No reason, just testing myself. If anyone else can make an even more compact version, that would be cool to see.

I know a lot of people don't care too much about this type of stuff, but I'm happy with how compact I managed to get it, working just as perfect as other larger ones.

Variable “a” will have the final encoded and decoded data.

Also, I know the variables and list are just a letter, this is for dramatic effects lol.

when green flag clicked
delete (all v) of [l v]
set [a v] to [abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+\][|}{';":/.,?>< ]
set [i v] to [1]
repeat (length of (a))
add (letter (i) of (a)) to [l v]
change [i v] by (1)
end

define encode (data)
set [a v] to []
set [i v] to [1]
repeat (length of (data))
set [a v] to (join (a) ((item # of (letter (i) of (data)) in [l v]) + (100)))
change [i v] by (1)
end

define decode (data)
set [a v] to []
set [i v] to [1]
repeat (length of ((data) / (3)))
set [p v] to (join (join (letter (((i) * (3)) - (2)) of (data)) (letter (((i) * (3)) - (1)) of (data))) (letter ((i) * (3)) of (data)))
set [a v] to (join (a) (item ((p) - (100)) of [l v] :: list))
change [i v] by (1)
end
alekhyo_0812
Scratcher
37 posts

Most compact Encoder & Decoder!

Good job! Did the same thing about a month back
alekhyo_0812
Scratcher
37 posts

Most compact Encoder & Decoder!

try this
set [encoded v] to []
set [i v] to [1]
repeat (length of (text))
set [encoded v] to (join (encoded) (join ( ( (letter (i) of (text)) )' ') ))
change [i v] by (1)
end


set [decoded v] to []
set [word v] to []
set [i v] to [1]
repeat (length of (encoded))
if <(letter (i) of (encoded)) = [ ]> then
set [decoded v] to (join (decoded) (letter (word) of [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!? ]))
set [word v] to []
else
set [word v] to (join (word) (letter (i) of (encoded)))
end
change [i v] by (1)
end

Last edited by alekhyo_0812 (Dec. 18, 2025 18:19:26)

alekhyo_0812
Scratcher
37 posts

Most compact Encoder & Decoder!

no lists
3 vars only

Powered by DjangoBB