Author Topic: Word Encoding/Decoding  (Read 10819 times)

0 Members and 1 Guest are viewing this topic.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Word Encoding/Decoding
« on: September 08, 2010, 10:17:04 pm »
Ok, so since I will be including a custom name for your character in the game I'm creating I decided I needed to come up with a way of converting words to a list so they could be stored without the worry of someone changing a string variable. But the only bad part about doing this is that normally you are limited to a seven character limit since normally each letter is two numbers and the calculator only can hold numbers of 14 numbers in length (and then it starts rounding and such, I believe; I just know 14 is the limit :P). So I did some looking around on here and found one topic, I think, that Raylin started that is about this but I wanted to create my own method for this (Raylin's topic is here).

Now, the code:

Note:
When ever you see "LW" the the code below it is really LW. Same with L2 and L1, but those are pretty well known now. Also, when you see "10^(" it is the actual token that you get when you press [2ND] then [LOG].

Code: (Encode) [Select]
DelVar LWDelVar LW15?dim(L2
DelVarB1?C
Input Str1
iPart((length(Str1)-1)/7+1?dim(LW
For(A,1,length(Str1
10^(B)inString("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz?0123456789",sub(Str1,A,1?L2(B+1
B+2?B
If B=14
Then
sum(L2?LW(C+1
C+1?C
DelVar BDelVar L215?dim(L2
End
End
C?LW(1
sum(L2?LW(C+1

Essentially what this is doing is that it makes a series of numbers based on where they are in the string. When the number gets up to fourteen numbers in length it increases the C variable by one and starts a new number to place in the next element, creating two numbers. Then C is stored to the first element to tell the decoder how many elements the word is.

Now the decoder's code:

Note:
When you see "E2" in the source code that is the scientific notation E.

Code: (Decode) [Select]
"_
For(A,1,LW(1
For(B,2,int(log(LW(A+1)))+2,2
Ans+sub("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz?0123456789",iPart(E2fPart(LW(A+1)10^(-B))),1
End
End
sub(Ans,2,length(Ans)-1?Str1

The thing I like about mine is that, one, the size of the program is basically dependent on what is in that string in the sub( command, two, it is pretty fast if I do say so myself (both the decoder and encoder; obviously though it takes longer with a bigger word) and, three, it is basically all self-working as long as you have the sub( string the way you want. No further math or anything needed (the strings just need to match).

I wouldn't doubt if there are a couple optimizations that could be made to those by the way.

Note:
There are only two downsides to this method. The first is that it is restricted to the 999 elements of a list. I don't forsee this being a huge issue though since you'd need a really long string to do that. (I think it's about 142 tokens but I'm not sure.) The other downside is that the strings that need to match must be under a hundred tokens long. This is because it uses only two numbers to store a token.
« Last Edit: October 31, 2011, 08:57:15 pm by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Word Encoding/Decoding
« Reply #1 on: September 08, 2010, 10:44:19 pm »
Code: [Select]
"_
For(A,1,dim(LW
For(B,1,.5+.5int(log(LW(A
Ans+sub("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzΘ0123456789",iPart(E2fPart(LW(A)/10^(2B))),1
End
End
sub(Ans,2,length(Ans)-1→Str1

i think this still works.. but it's late, and i'm tired, so i'm not completely sure.
« Last Edit: September 08, 2010, 10:46:17 pm by nemo »


Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Word Encoding/Decoding
« Reply #2 on: September 08, 2010, 10:52:32 pm »
Ya, that actually does seem to work. Thanks. Shaved off six bytes :)
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Word Encoding/Decoding
« Reply #3 on: September 11, 2010, 09:14:39 pm »
*Bump*

Did people see this? Just thought this might be useful to some people :)
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Word Encoding/Decoding
« Reply #4 on: September 11, 2010, 11:47:06 pm »
I assume this converts char names to lists? I generally just store my char names into a list, although the way I did it in my old games isn't too efficient, due to each letter taking 1 list element. I would have been better with some compression.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Word Encoding/Decoding
« Reply #5 on: September 11, 2010, 11:58:03 pm »
Well technically this can be used to store any string to a list. It stores every seven tokens (or less) to a element and then goes on to the next element if needed. Then it stores how many elements were used to the first element. I just thought I would provide this since it has no limit on size, besides the list restriction of 999 elements.

But in short, yes, this converts a characters name to a list :P
« Last Edit: September 11, 2010, 11:58:40 pm by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Word Encoding/Decoding
« Reply #6 on: September 11, 2010, 11:58:57 pm »
Aaah ok I see :)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Word Encoding/Decoding
« Reply #7 on: September 12, 2010, 12:03:24 am »
Ya. This also isn't limited by to a certain number of tokens that can be used. As long as the strings match you can put what ever you want. Also, the string is basically what decides how big the routine is :D
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Word Encoding/Decoding
« Reply #8 on: September 12, 2010, 02:35:03 am »
Yeah true and since it's TI-BASIC, you can also use the 2 byte tokens. In Axe it can be a major PITA, sometimes.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Word Encoding/Decoding
« Reply #9 on: September 12, 2010, 02:42:40 am »
Ya, I think it'll come in handy. I mean it's a pretty simple routine and method (I think at least).
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Word Encoding/Decoding
« Reply #10 on: September 12, 2010, 02:46:01 pm »
I forgot to mention that the only downside about this is that it won't work if your string is over a hundred tokens long. I'll edit that into the first post too.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Word Encoding/Decoding
« Reply #11 on: September 12, 2010, 02:50:10 pm »
Ah ok I see. I doubt much people would need to use strings that large, though, since it would be at their disadvantage, kinda (memory-wise)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Word Encoding/Decoding
« Reply #12 on: September 12, 2010, 02:54:26 pm »
Ya, that's what I thought too. I don't even think there are a hundred tokens that you would use for typing anyways. But I don't know. Just thought I'd mention it just in case :P
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline holmes221b

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 282
  • Rating: +13/-1
  • RESISTANCE IS FUTILE.
    • View Profile
    • My Livejournal
Re: Word Encoding/Decoding
« Reply #13 on: January 07, 2011, 05:53:47 pm »
Can this be used to translate numbers in a matrix into letters?
* holmes221b is thinking that this could be exactly what she needs for QFIBCODE....

Spoiler For "Projects":
Spoiler For "Because Everyone Else Is":
*Sigh*
can we keep this on topic? The topic is about what the big thing might be, NOT SEX

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Word Encoding/Decoding
« Reply #14 on: January 07, 2011, 06:01:36 pm »
Code: [Select]
"_
For(A,1,dim(LW
For(B,1,.5+.5int(log(LW(A
Ans+sub("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzΘ0123456789",iPart(E2fPart(LW(A)/10^(2B))),1
End
End
sub(Ans,2,length(Ans)-1→Str1

i think this still works.. but it's late, and i'm tired, so i'm not completely sure.

i can't even read that anymore... i'm spoiled by java

and yeah holmes this could be used with some modification for a matrix.
« Last Edit: January 07, 2011, 06:02:10 pm by nemo »