Encoding input.
Malphas
12 Sept 2022, 19:48Hello everybody, I'm making progress slowly but surely.
However I was curious about encryption and found this: http://textadventures.co.uk/forum/quest/topic/ibk2irzb7kwmddhrnrnfqq/text-scrambler-doo-hickey-thing#abacd36e-79fb-4467-b943-d3df6b0d9b7d
With a few slight alterations that code was the key to the encryption, type something and it gets assigned a random number and encrypted by it. The code is below this block of text.
It leaves me with a problem though, I can't find a way to set a variable to the completed encrypted text since every letter is done one by one. That means if I try to do use game.t it only gives the last letter.
Any ideas on how to get the completed text set to a variable?
Thanks for the help and sorry for the horrendous layout.
game.s = "1"
GetInput() {
game.a = result
for (k, 1, LengthOf(game.a), 1) {
game.l = k-(k/7)*7+1
t = Asc(Mid(game.a,k,1))+(ToInt(game.s)*ToInt(Mid(game.n,game.l,1)))
if (t>90 or t<65) {
t = t-(ToInt(game.s)%26)
}
OutputTextNoBr ("<samp style=\"background:black;color:green;\">" +Chr(t))
game.t = Chr(t)
}
}
mrangel
12 Sept 2022, 20:44I can't really follow that algorithm. I assume game.n
is some kind of encryption key… an 8-digit number giving the distance to offset each character by?
You have game.l = k-(k/7)*7+1
, which as far as I can tell is the same as game.l = k % 7 + 1
with a couple of extra steps. But this attribute is only used once, and I can't see any reason you would need to save it for use after this script.
If this is supposed to be some kind of encryption, it seems that it's a little broken (the way it handles character values that aren't uppercase letters means that there will be multiple strings that generate the same encrypted value, so it can't be reliably decrypted)
In any case, if you want to save the whole string:
- At the start, create an attribute to store the encrypted version:
game.encryptedstring = ""
- At the end of the
for
loop, after generating the next character, add it to the string:
game.encryptedstring = game.encryptedstring + Chr (t)
Malphas
13 Sept 2022, 05:45Thank you mrangel, I will give it a shot!
Also about the game.n, that's a line I apparently forgot to copy here, it's:
game.n = ToString (GetRandomInt(1000000, 9999999))
So it's just a random 7 digit number
Thanks again for the help!
Malphas
13 Sept 2022, 05:57Alright, just tested it out and it worked wonders.
At the risk of repeating myself once again, thank you very much mrangel!