I wanted to have a ROT13 encoder in place in order to display hint information for myself in a tester’s transcript. For instance, a player would be able to say “HINT” and that would show a location-specific hint in a test build. But I don’t want to ruin that for the first time player–though I want to be sure the hints would be reasonable if he could see them. So I could have them set a flag that obfuscates the hint, then read their transcript.
But ROT13 seems very slow with indexed text, at least in the couple ways I tried to implement it. I’ve tried two ways and each takes a few seconds within the IDE or a built zblorb. Is there a quicker way than my source? I read in the docs that we don’t track the ASCII number of values, so I can’t do any math tricks to replace the perl-ish cheap and dirty tr/[a-z]/[m-za-o]/y.
Now, I think a better solution is ultimately to just send the player’s latest command and the game’s hint to a text file, but I’m curious about if there’s a way to speed any ROT13 up.
Thanks again!
[code]“rot13” by Andrew
room 1 is a room.
every turn:
test-reg-expr;
to test-reg-expr:
let xyz be indexed text;
now xyz is “Yay”;
say “[xyz].”;
say “[the rot13 of xyz].”;
now xyz is “The quick brown fox jumped over the lazy dog”;
say “[xyz].”;
say “[the rot13 of xyz].”;
now xyz is “Another test, this one to see if things really slow down”;
say “[xyz].”;
say “[the rot13 of xyz].”;
table of rot13
from to
“a” “n”
“b” “o”
“c” “p”
“d” “q”
“e” “r”
“f” “s”
“g” “t”
“h” “u”
“i” “v”
“j” “w”
“k” “x”
“l” “y”
“m” “z”
to decide what indexed text is the rot13 of (aa - indexed text):
let twiddled-yet be a truth state;
let A be AA;
repeat with B running from 1 to the number of characters in A:
now twiddled-yet is false;
repeat through the table of rot13:
if twiddled-yet is false:
if character number B in A in lower case is “[from entry]”:
replace character number B in A with “[to entry]”;
now twiddled-yet is true;
otherwise if character number B in A in lower case is “[to entry]”:
replace character number B in A with “[from entry]”;
now twiddled-yet is true;
decide on “[A]”;
to decide what indexed text is the encodation of (aa - indexed text):
let twiddled-yet be a truth state;
let A be AA;
let D be a number;
repeat with B running from 1 to the number of characters in A:
now twiddled-yet is false;
repeat with C running from 1 to the number of entries in Q:
if character number B in A in lower case is “[entry C of Q]” and twiddled-yet is false:
now D is rotationkey + C;
if D > number of entries in Q:
now D is D - number of entries in Q;
replace character number B in A with entry D of Q;
now twiddled-yet is true;
decide on “[A]”;
rotationkey is a number that varies. rotationkey is usually 13. [this allows for not just ROT13]
Q is a list of text which varies. Q is { “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z” };[/code]