Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Leaderboard encryption and decryption
- StrangeMagic32
-
1000+ posts
Leaderboard encryption and decryption
I am trying to make a leaderboard, yet I don't know how to or where to start in making an encryption and decryption system to save the name of the top player.
Project: https://scratch-mit-edu.ezproxyberklee.flo.org/projects/238451124/
Project: https://scratch-mit-edu.ezproxyberklee.flo.org/projects/238451124/
- StrangeMagic32
-
1000+ posts
Leaderboard encryption and decryption
https://en.scratch-wiki.info/wiki/Global_High_ScoresI can't access that rn is there an alternative that could work too?
Last edited by StrangeMagic32 (Aug. 7, 2018 15:45:32)
- ShinigamiBlacky
-
100+ posts
Leaderboard encryption and decryption
what do you meam, you cant access it?
- StrangeMagic32
-
1000+ posts
Leaderboard encryption and decryption
I have internet restrictions at the moment what do you meam, you cant access it?
- deck26
-
1000+ posts
Leaderboard encryption and decryption
You mean encoding rather than encryption? Just a case of looking at each character in turn and working out its position in a string of allowed characters. So if the string is ‘ABCDEFG……XYZ0123456789’ my username encodes as 040503112933 - note that single digit values need expanding to 2 digits. To decode you just take two digits and use that in a ‘letter n of string’ block then move to the next pair and repeat.
Just basic looping and matching characters to encode.
Just basic looping and matching characters to encode.
- --_Nova_--
-
1000+ posts
Leaderboard encryption and decryption
Don't worry - I'll copy all the code over for you.I have internet restrictions at the moment what do you meam, you cant access it?
Encoding
During the encoding process, each character or number in a list item is represented by a two-digit number. For example, “a” would be the digit “01” and “b” the digit “02”. The list “characters” stores as many as 99 characters to encode. If there were 100 or more characters readable by the global high score system, each character would have to be represented by a three-digit value. The order the characters go in this list does not matter; they just have to be consistent throughout the encoding process.
Therefore, each list item (i.e. a user and his or her score) is separated by “00”. Without it, the script could not separate the list items properly, and all the characters would be a large jumble.
After the list is filled out with available computer characters, the cloud variable encoding script can be made. It is a long process encoding the data.
define encode
set [list item v] to [1]
set [☁ leaderboard v] to []
repeat (length of [users v])
set [letter detect v] to [1]
set [letter# v] to [1]
repeat (length of (item (list item) of [users v]
set [letter detect v] to [1]
repeat until <(letter (letter#) of (item (list item) of [users v])) = (item (letter detect) of [letter v]
change [letter detect v] by (1)
end
if <(letter detect) < [10]> then
set [☁ leaderboard v] to (join(☁ leaderboard)(join [0] (letter detect))
else
set [☁ leaderboard v] to (join(☁ leaderboard)(letter detect))
end
change [letter# v] by (1)
end
set [☁ leaderboard v] to (join(☁ leaderboard) [00])
set [letter detect v] to [1]
set [letter# v] to [1]
repeat (length of (item (list item) of [scores v]))
set [letter detect v] to [1]
repeat until <(letter (letter#) of (item (list item) of [scores v])) = (item (letter detect) of [letter v]
change [letter detect v] by (1)
end
if <(letter detect) < [10]>then
set [☁ leaderboard v] to (join (☁ leaderboard)(join [0] (letter detect))
else
set [☁ leaderboard v] to (join (☁ leaderboard)(letter detect))
end
change [letter# v] by (1)
end
set [☁ leaderboard v] to (join (leaderboard)[00])
change [list item v] by (1)
Decoding
Decoding is the process by which the numerically encoded data is decoded, or taken out of number format and compiled into the two lists again. Decoding checks for the “00” placed between list items during the encoding to determine when to iterate to the next list item. After the process is complete, the lists will be arranged in the manner prior to the encoding.
define decode
set [letter# v] to [0]
set [letter detect v] to [1]
delete (all v) of [users v]
delete (all v) of [scores v]
add [] to [users v]
add [] to [scores v]
repeat until <(letter#) > ((length of (☁ leaderboard)) - (1))>
repeat until <(join (letter ((letter#) + (1)) of (☁ leaderboard)) (letter ((letter#) + (2)) of (☁ leaderboard))) = [00]>
set [letter detect v] to [1]
repeat until <(letter detect) = (join (letter ((letter#) + (1)) of (☁ leaderboard)) (letter ((letter#) + (2)) of (☁ leaderboard)))>
change [letter detect v] by (1)
if <(letter detect) < [10]> then
set [letter detect v] to (join [0] (letter detect))
end
end
if <(letter (1) of (letter detect)) = [0]> then
set [letter detect v] to (letter (2) of (letter detect))
end
replace item (last v) of [users v] with (join (item (last v) of [users v]) (item (letter detect) of [letter v]))
change [letter# v] by (2)
end
change [letter# v] by (2)
repeat until <(join (letter ((letter#) + (1)) of (☁ leaderboard)) (letter ((letter#) + (2)) of (☁ leaderboard))) = [00]>
set [letter detect v] to [1]
repeat until <(letter detect) = (join (letter ((letter#) + (1)) of (☁ leaderboard)) (letter ((letter#) + (2)) of (☁ leaderboard)))>
change [letter detect v] by (1)
end
replace item (last v) of [scores v] with (join (item (last v) of [scores v]) (item (letter detect) of [letter v]))
change [letter# v] by (2)
end
add [] to [users v]
add [] to [scores v]
change [letter# v] by (2)
end
delete (last v) of [users v]
delete (last v) of [scores v]
Tell me if you need the other scripts.
Last edited by --_Nova_-- (Aug. 7, 2018 18:21:12)
- StrangeMagic32
-
1000+ posts
Leaderboard encryption and decryption
So I have 2 variables already and I'm wondering if my
(Item)and
(☁ World Highscore)are the equivalents to your
(list item)and
(☁ leaderboard)
Last edited by StrangeMagic32 (Aug. 8, 2018 14:49:11)
- --_Nova_--
-
1000+ posts
Leaderboard encryption and decryption
I believe so, though I don't know their functions So I have 2 variables already and I'm wondering if my(Item)and(☁ World Highscore)are the equivalents to your(list item)and(☁ leaderboard)
- Coding_Boy
-
26 posts
Leaderboard encryption and decryption
My Text-Code Conversion project shows how to encode and decode data. You can look inside to see how it works, and you can copy it if you please. To put it simply, you can encode your data for the leaderboard and save that code to a cloud variable. Then it will decode whatever the cloud variable's value is across every project.
- NilsTheBest
-
1000+ posts
Leaderboard encryption and decryption
Holy moly, that is some intense coding. I'm definitely going to look into this in the future.
I don't quite understand everything here but It's very helpful, that's what I've been trying to do for a game that I published about a month ago.
Thanks for sharing the link
I don't quite understand everything here but It's very helpful, that's what I've been trying to do for a game that I published about a month ago.
Thanks for sharing the link

- Discussion Forums
- » Help with Scripts
-
» Leaderboard encryption and decryption