So I was working on some games and I thought of a routine that would allow for an infinite number of strings using lists.
(If this has already been done, please direct me to the correct forum post)
Here's the compression routine:
length(Str1)→M
iPart((M-1)/6)+1→dim(L₁
Fill(1,L₁
For(X,M,1,-1)
sub(Str1,X,1
inString(Str0,Ans)→T
iPart((X-1)/6)+1
L₁(Ans)E2+T→L₁(Ans
End
(From here you would store L₁ to whatever list you want and clean up everything else)
And the decompression:
"A"→Str1 //This can be any character.
For(L,1,dim(L₁)) //Replace L₁ with the appropriate list name
L₁(L)→T
Repeat T=1
T/E2→T
fPart(T)→U
Str1+sub(Str0,UE2,1)→Str1
T-U→T
End
End
sub(Str,2,length(Str1)-1)→Str1 //This removes that first "filler" character
How it all works:
The compression routine turns Str1 into a series of codes, with each character corresponding to a 2 digit number. The routine automatically puts 6 character codes per list entry (any more codes would render the number incomprehensible beyond the first 10 or so digits). The routine also makes the first digit of every entry a "1". This will prevent "08-22" from being read as "82-2", because it keeps the zero: "1-08-22". (The "1" is also used as the condition for the decompression Repeat loop).
The decompression routine does the exact opposite by taking each code, finding the appropriate character, and adding it to Str1. It will repeat the process for all entries in L₁ or whatever list is used. The filler character is used at the beginning because you cannot add characters to an empty string.
The final thing to mention about this is Str0. Str0 is the "cipher string". The string is composed of all the characters that will ever be used by the system. On my personal TI 84+CSE, Str0 is "AaBbCcDd…" followed by all necessary punctuation and a space. It doesn't matter what characters are in the string, as long as it is the same for both compression and decompression, because the character codes correspond to that character's inString value for Str0, and thus must be the same in order to be deciphered correctly using the sub( command.
Again, if this has been done before, please direct me to the correct forum post. If not, I would love some feedback on how to optimize the compression/decompression. Thanks!